Skip to content

Commit

Permalink
Merge pull request #18 from iSevenDays/feature/additional_scan_folders
Browse files Browse the repository at this point in the history
Additional scan folders
  • Loading branch information
curvedinf authored Jan 13, 2025
2 parents 1620d5b + c137425 commit d93b4ba
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,14 @@ dir-assistant
Running `dir-assistant` will scan all files recursively in your current directory. The most relevant files will
automatically be sent to the LLM when you enter a prompt.

### Additional scan folders

You can include files from folders outside your current directory:

```shell
dir-assistant start --additional-scan-folders "/path/to/folder1,/path/to/folder2"
```

### Ignoring files

You can ignore files when starting up so they will not be included in the assistant's context:
Expand Down Expand Up @@ -382,4 +390,4 @@ please see [CONTRIBUTORS.md](CONTRIBUTORS.md).

## Additional Credits

Special thanks to [Blazed.deals](https://blazed.deals) for sponsoring this project.
Special thanks to [Blazed.deals](https://blazed.deals) for sponsoring this project.
11 changes: 10 additions & 1 deletion dir_assistant/assistant/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,20 @@ def get_files_with_contents(directory, ignore_paths, cache_db):
return files_with_contents


def create_file_index(embed, ignore_paths, embed_chunk_size):
def create_file_index(embed, ignore_paths, embed_chunk_size, additional_folders=[]):
cache_db = get_file_path(INDEX_CACHE_PATH, INDEX_CACHE_FILENAME)

print(f"{Fore.LIGHTBLACK_EX}Finding files to index...{Style.RESET_ALL}")
# Start with current directory
files_with_contents = get_files_with_contents(".", ignore_paths, cache_db)

# Add files from additional folders
for folder in additional_folders:
if os.path.exists(folder):
folder_files = get_files_with_contents(folder, ignore_paths, cache_db)
files_with_contents.extend(folder_files)
else:
print(f"{Fore.LIGHTBLACK_EX}Warning: Additional folder {folder} does not exist{Style.RESET_ALL}")
chunks = []
embeddings_list = []
with SqliteDict(cache_db, autocommit=True) as cache:
Expand Down
7 changes: 5 additions & 2 deletions dir_assistant/cli/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ def start(args, config_dict):
exit(1)

ignore_paths = args.i__ignore if args.i__ignore else []
additional_folders = []
if args.additional_scan_folders:
additional_folders = [f.strip() for f in args.additional_scan_folders.split(",")]
ignore_paths.extend(config_dict["GLOBAL_IGNORES"])

# Initialize the embedding model
Expand All @@ -123,7 +126,7 @@ def start(args, config_dict):

# Create the file index
print(f"{Fore.LIGHTBLACK_EX}Creating file embeddings and index...{Style.RESET_ALL}")
index, chunks = create_file_index(embed, ignore_paths, embed_chunk_size)
index, chunks = create_file_index(embed, ignore_paths, embed_chunk_size, additional_folders)

# Set up the system instructions
system_instructions_full = f"{system_instructions}\n\nThe user will ask questions relating \
Expand Down Expand Up @@ -192,4 +195,4 @@ def start(args, config_dict):
print(f"\n{Style.BRIGHT}Rolled back to the previous commit.{Style.RESET_ALL}\n\n")
continue
else:
llm.stream_chat(user_input)
llm.stream_chat(user_input)
5 changes: 5 additions & 0 deletions dir_assistant/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ def main():
nargs="+",
help="A list of space-separated filepaths to ignore.",
)
parser.add_argument(
"--additional-scan-folders",
type=str,
help="Comma-separated list of additional folders to scan",
)

mode_subparsers = parser.add_subparsers(
dest="mode", help="Run dir-assistant in regular mode"
Expand Down

0 comments on commit d93b4ba

Please sign in to comment.