This commit is contained in:
112
.cli_memory/commands/suggestions.py
Normal file
112
.cli_memory/commands/suggestions.py
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
import click
|
||||||
|
from rich import print as rprint
|
||||||
|
from rich.panel import Panel
|
||||||
|
from rich.table import Table
|
||||||
|
|
||||||
|
from ..config import Config
|
||||||
|
from ..database import Database
|
||||||
|
from ..suggestions import SuggestionEngine
|
||||||
|
|
||||||
|
|
||||||
|
@click.group()
|
||||||
|
def suggest():
|
||||||
|
"""Get smart command suggestions."""
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@suggest.command()
|
||||||
|
@click.argument("prefix")
|
||||||
|
@click.option("--project", "-p", help="Project ID")
|
||||||
|
@click.option("--limit", "-l", default=5, help="Maximum suggestions")
|
||||||
|
def next(prefix, project, limit):
|
||||||
|
"""Get suggestions for next command."""
|
||||||
|
db = Database()
|
||||||
|
engine = SuggestionEngine(db=db)
|
||||||
|
|
||||||
|
project_id = int(project) if project else None
|
||||||
|
suggestions = engine.get_suggestions(prefix, project_id=project_id, limit=limit)
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
if not suggestions:
|
||||||
|
rprint(f"[yellow]No suggestions for: {prefix}[/yellow]")
|
||||||
|
return
|
||||||
|
|
||||||
|
table = Table(title=f"Suggestions for: {prefix}")
|
||||||
|
table.add_column("Command", style="cyan")
|
||||||
|
table.add_column("Confidence", style="magenta")
|
||||||
|
table.add_column("Frequency", style="green")
|
||||||
|
|
||||||
|
for s in suggestions:
|
||||||
|
table.add_row(
|
||||||
|
s.command,
|
||||||
|
f"{s.confidence:.2%}",
|
||||||
|
str(s.frequency),
|
||||||
|
)
|
||||||
|
|
||||||
|
rprint(Panel(table, title="Suggestions"))
|
||||||
|
|
||||||
|
|
||||||
|
@suggest.command()
|
||||||
|
@click.argument("prefix")
|
||||||
|
@click.option("--project", "-p", help="Project ID")
|
||||||
|
def autocomplete(prefix, project):
|
||||||
|
"""Get autocomplete candidates."""
|
||||||
|
db = Database()
|
||||||
|
engine = SuggestionEngine(db=db)
|
||||||
|
|
||||||
|
project_id = int(project) if project else None
|
||||||
|
candidates = engine.get_autocomplete_candidates(prefix, project_id)
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
if candidates:
|
||||||
|
rprint("[cyan]Autocomplete candidates:[/cyan]")
|
||||||
|
for c in candidates:
|
||||||
|
rprint(f" {c}")
|
||||||
|
else:
|
||||||
|
rprint(f"[yellow]No autocomplete candidates for: {prefix}[/yellow]")
|
||||||
|
|
||||||
|
|
||||||
|
@suggest.command()
|
||||||
|
def train():
|
||||||
|
"""Train suggestion engine."""
|
||||||
|
db = Database()
|
||||||
|
engine = SuggestionEngine(db=db)
|
||||||
|
|
||||||
|
engine.train()
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
rprint("[green]Suggestion engine trained successfully![/green]")
|
||||||
|
|
||||||
|
|
||||||
|
@suggest.command()
|
||||||
|
@click.option("--project", "-p", help="Project ID")
|
||||||
|
def patterns(project):
|
||||||
|
"""Show detected patterns."""
|
||||||
|
db = Database()
|
||||||
|
engine = SuggestionEngine(db=db)
|
||||||
|
|
||||||
|
project_id = int(project) if project else None
|
||||||
|
patterns = engine.get_pattern_suggestions(project_id)
|
||||||
|
|
||||||
|
db.close()
|
||||||
|
|
||||||
|
if not patterns:
|
||||||
|
rprint("[yellow]No patterns detected yet[/yellow]")
|
||||||
|
return
|
||||||
|
|
||||||
|
table = Table(title="Detected Patterns")
|
||||||
|
table.add_column("Name", style="cyan")
|
||||||
|
table.add_column("Commands", style="magenta")
|
||||||
|
table.add_column("Occurrences", style="green")
|
||||||
|
table.add_column("Confidence", style="yellow")
|
||||||
|
|
||||||
|
for p in patterns[:20]:
|
||||||
|
cmds = " | ".join(p.command_sequence[:3])
|
||||||
|
if len(p.command_sequence) > 3:
|
||||||
|
cmds += " | ..."
|
||||||
|
table.add_row(p.name, cmds, str(p.occurrences), f"{p.confidence:.2%}")
|
||||||
|
|
||||||
|
rprint(Panel(table, title="Patterns"))
|
||||||
Reference in New Issue
Block a user