sourcegraph / cody

Type less, code more: Cody is an AI code assistant that uses advanced search and codebase context to help you write and fix code.
https://cody.dev
Apache License 2.0
2.59k stars 275 forks source link

bug: Discover .git (and .cody) root #3157

Closed RXminuS closed 2 months ago

RXminuS commented 7 months ago

Version

1.86

Describe the bug

Right now any feature that relies on the .git project path (such as .cody ignore, https://github.com/sourcegraph/cody/pull/2306#issuecomment-1938672543 ) assumes that the project root is the VSCode workspace root. However it frequently happens that the project .git folder can be up a few levels in the directory structure from the Workspace root which then breaks the feature.

For instance, the .cody ignore file isn't found if the folder is above the current workspaceUri.

This can easily be reproduced by simply adding a sub-folder to the workspace.

Expected behavior

Just like the default VSCode Git extension there should be a method to get the "real" project root that walks up the path tree until it encounters a .git/.cody directory. This way.cody-ignore and features like below can construct paths relative to this root instead of the workspaceUri

Additional context

Example workspaceUri path that should be project root relative: https://github.com/sourcegraph/cody/blob/4756dc7fc8a08998421fe7c3aa6d4d461327a31a/vscode/src/scm/CommitMessageProvider.ts#L220

dominiccooney commented 7 months ago

@taylorsperry, some users want Cody to walk the directory tree to discover repository roots; other users don't want Cody to walk the directory tree so they can control the scope of Cody's filesystem access. How will we resolve this apparent contradiction?

RXminuS commented 7 months ago

What is it about the file system access that users want to control?

Because my totally unresearched, uniformed, self centered assumption would be that it's primarily from the concern that no confidential information should ever be leaked to a hosted LLM by "context expansion" outside of the walled garden of the workspace.

In this particular case that's exactly what i wanted to use the real project root for is to ensure that files that VSCode has exposed as changed in git don't accidentally get included in a prompt (in this case the commit message generator). To do this I need to resolve the path relative to the .git folder. Similarly if a user has a .cody folder in the directory chain with configuration it feels sort of rude and counterintuitive to ignore it just because I happened to open a sub folder as a workspace. Especially if that means that the rules in codyignore are now ignored and it potentially does expose information I thought was sealed off.

So if that's the feedback I don't think those two goals are necessarily disjoint.

github-actions[bot] commented 3 months ago

This issue is marked as stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed automatically in 5 days.