chore: initial commit

Co-authored-by: Lifei Zhou <lifei@squareup.com>
Co-authored-by: Mic Neale <micn@tbd.email>
Co-authored-by: Lily Delalande <ldelalande@squareup.com>
Co-authored-by: Bradley Axen <baxen@squareup.com>
Co-authored-by: Andy Lane <alane@squareup.com>
Co-authored-by: Elena Zherdeva <ezherdeva@squareup.com>
Co-authored-by: Zaki Ali <zaki@squareup.com>
Co-authored-by: Salman Mohammed <smohammed@squareup.com>
This commit is contained in:
Luke Alvoeiro
2024-08-23 16:39:04 -07:00
commit dd126afa6c
68 changed files with 4498 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
from functools import cache
from typing import Dict
from goose.command.base import Command
from goose.utils import load_plugins
@cache
def get_command(name: str) -> type[Command]:
return load_plugins(group="goose.command")[name]
@cache
def get_commands() -> Dict[str, type[Command]]:
return load_plugins(group="goose.command")
+16
View File
@@ -0,0 +1,16 @@
from abc import ABC
from typing import List, Optional
from prompt_toolkit.completion import Completion
class Command(ABC):
"""A command that can be executed by the CLI."""
def get_completions(self, query: str) -> List[Completion]:
"""Get completions for the command."""
return []
def execute(self, query: str) -> Optional[str]:
"""Execute's the command and replaces it with the output."""
return ""
+61
View File
@@ -0,0 +1,61 @@
import os
from typing import List
from prompt_toolkit.completion import Completion
from goose.command.base import Command
class FileCommand(Command):
def get_completions(self, query: str) -> List[Completion]:
if query.startswith("/"):
directory = os.path.dirname(query)
search_term = os.path.basename(query)
else:
directory = os.path.join(os.getcwd(), os.path.dirname(query))
search_term = os.path.basename(query)
# if query is a file, don't show completions
if os.path.isfile(directory):
return []
# Get the list of files in the directory
options = []
try:
for file_name in os.listdir(directory):
if file_name.startswith(search_term):
full_path = os.path.join(directory, file_name)
if os.path.isdir(full_path):
options.append(
dict(
display_text="" + file_name,
insert_text=file_name,
is_dir=True,
)
)
else:
options.append(
dict(
display_text="" + file_name,
insert_text=file_name + " ",
is_dir=False,
)
)
except FileNotFoundError:
return []
completions = []
options.sort(key=lambda x: (not x["is_dir"], x["insert_text"]), reverse=False)
for option in options:
completions.append(
Completion(
option["insert_text"],
start_position=-len(search_term),
display=option["display_text"],
)
)
return completions
def execute(self, query: str) -> str | None:
# GOOSE-TODO: return the query
pass