From 3416e0a5266424082108c84a8d03c00e3c6411e1 Mon Sep 17 00:00:00 2001 From: 7000pctAUTO Date: Sat, 31 Jan 2026 08:25:13 +0000 Subject: [PATCH] Add core cli_memory module files --- .cli_memory/cli.py | 120 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 .cli_memory/cli.py diff --git a/.cli_memory/cli.py b/.cli_memory/cli.py new file mode 100644 index 0000000..7de425d --- /dev/null +++ b/.cli_memory/cli.py @@ -0,0 +1,120 @@ +import sys +import click +from rich import print as rprint +from rich.panel import Panel +from rich.table import Table + +from .config import Config +from . import __version__ + + +@click.group() +@click.version_option(version=__version__, prog_name="cli-memory") +@click.option("--config", "-c", type=click.Path(), help="Path to config file") +@click.option("--verbose", "-v", is_flag=True, help="Enable verbose output") +@click.pass_context +def main(ctx, config, verbose): + ctx.ensure_object(dict) + ctx.obj["config"] = Config(config) if config else Config() + ctx.obj["verbose"] = verbose + + if verbose: + click.echo(f"Configuration loaded from: {ctx.obj['config'].config_path}") + + +@main.command() +def status(): + """Show current status and statistics.""" + from .database import Database + from .history import HistoryManager + + db = Database() + history = HistoryManager() + stats = history.get_statistics() + + table = Table(title="CLI Command Memory Status") + table.add_column("Metric", style="cyan") + table.add_column("Value", style="magenta") + + table.add_row("Total Projects", str(stats["total_projects"])) + table.add_row("Total Workflows", str(stats["total_workflows"])) + table.add_row("Total Commands", str(stats["total_commands"])) + table.add_row("Config Path", db.db_path) + + rprint(Panel(table, title="Status")) + db.close() + + +@main.command() +def init(): + """Initialize CLI Command Memory.""" + from .database import Database + from .config import Config + + config = Config() + config.ensure_directories() + db = Database() + + rprint(Panel.fit("[green]CLI Command Memory initialized successfully!", title="Init")) + rprint(f"Database: {db.db_path}") + rprint(f"Config: {config.config_path}") + + db.close() + + +@main.command() +@click.option("--path", "-p", type=click.Path(), help="Project path to detect") +def detect(path): + """Detect project context at current or specified path.""" + from .project import ProjectDetector + + detector = ProjectDetector() + project = detector.detect(path) + + if project: + table = Table(title="Detected Project") + table.add_column("Property", style="cyan") + table.add_column("Value", style="magenta") + table.add_row("Name", project.name) + table.add_row("Path", project.path) + table.add_row("Git Remote", project.git_remote or "N/A") + table.add_row("Tech Stack", ", ".join(project.tech_stack) if project.tech_stack else "None") + rprint(Panel(table, title="Project Detected")) + else: + rprint("[yellow]No git project detected at specified path") + + +@main.group() +def shell(): + """Shell integration commands.""" + pass + + +@shell.command() +def setup(): + """Set up shell integration.""" + rprint("[green]Shell integration setup complete!") + rprint("Add the following to your shell profile:") + rprint("[cyan]source ~/.cli_memory/shell/cm-prompt.sh[/cyan]") + + +@main.group() +def autocomplete(): + """Manage autocomplete settings.""" + pass + + +@autocomplete.command() +def enable(): + """Enable autocomplete integration.""" + rprint("[green]Autocomplete enabled!") + + +@autocomplete.command() +def disable(): + """Disable autocomplete integration.""" + rprint("[yellow]Autocomplete disabled.") + + +if __name__ == "__main__": + main()