New in v11.14.0 - ✨ Workspace slash command #705
Replies: 2 comments
-
Currently, I have implemented a similar context management mechanism toy for myself, with the primary goal of providing more comprehensive context for inline completions. Overall, it leverages the telescope plugin to allow users to bind other files that the current file depends on, enabling file context awareness. This ensures that the model can see sufficient dependency context when performing inline completions in the current file. For various languages, this implementation can parse the import statements at the beginning of each file to determine which files need to be imported. It also allows referencing user-specified dependency files and then solidifies them into a "current_file 2 group files context" format. I believe that the concept of "group" mentioned in workfspace could also adopt this approach in long-term planning. For a project, we could maintain a group files context for each buffer or each file it depends on. To reduce complexity, regular expression matching could be supported to ensure that certain types of files share the same group files context. This would guarantee that the model has access to optimal contextual dependencies for every task performed on any given file within a project. So, in the long-term plan, perhaps we can add features like these:
|
Beta Was this translation helpful? Give feedback.
-
Wow @olimorris your vision and perspective could not align more with my own if I tried! This is so amazing! I was just thinking a couple days ago about implementing my own version of something very similar to this feature! Now I don't have to ;) My initial thoughts on "next iterations" of this feature: A way to create, modify, add, remove to a Group in the app (thinking just like the /files with Telescope where you can select multiple files to add as references... we could similarly select multiple files to add to a Group that is stored in the workspace json. And then to modify a group could similarly show with telescope all the files as part of the group and then can select items to remove (as an example). Amazing work as usual! |
Beta Was this translation helpful? Give feedback.
-
The new workspace slash command allows users to share defined groups of files and/or symbols with an LLM, alongside some pre-written context. Think of it as a context management system
Background
For as long as I can remember on this project, I've wanted to add the ability for users to share their workspace with an LLM. That is, to be able to share their project/repo files and have a direct conversation about them. Alas, there were many things that I needed to figure out and implement before I could (91adfac, 767efee, 9c41484 and whatever the commit hashes are for the chat buffer messages table).
The @workspace tool in Copilot Chat served as the initial inspiration but over time I found it to be near ineffective. To get any real output from Copilot you need to send copious amounts of context over and it will never understand the technical and architectural decisions that you made in your project.
As I approached the start of this year, I began to think deeply about how I'd support workspaces in the plugin. I toyed with the idea of having a frecency algorithm coupled with a project hierarchy function to understand how files were structured and how they were being used across the repo. But soon remembered algorithms ≠ context. And my biggest learning of working with LLMs for around 18+ months (both professionally and personally) is that the quality of the context is directly proportional to the quality of the output.
So it was somewhat fortuitous that I came across an amazing blog post entitled "The day I taught AI to read code like a Senior Developer" at the start of January. The long and the short of it:
and as a result:
...that was the spark I needed to define the end goal and implement the workspace slash command.
How it works
The plugin uses a
codecompanion-workspace.json
file in the root of the current working directory. This groups files together with the output being the complete file or the symbolic outline of the file, surrounded by context that the user has defined themselves (...or perhaps asked an LLM to write part of). This combination is then shared with the LLM. The slash command will iterate through each file in thefiles
orsymbols
array adding them sequentially.You can see an example here. Although please note, I'll be tweaking this significantly over the coming days. I've released this feature a little earlier than planned so I can start using it to solve some current open issues.
Usage
codecompanion-workspace.json
file in the root of your current working directory/workspace
command and select a groupgd
Managing expectations
Whilst I have no evidence for this, I suspect that most users would have expected and wanted a command to automatically feed relevant files into the chat buffer, perhaps with some added context. For those that still think that, I'd ask them to read the blog post and align to their experiences of coding with LLMs. Failing that, it's relatively easy to load files into a chat buffer, programmatically with Lua (#641).
Other points to note
@files
tool has aread_lines
method to be able to get the content between two line numbers (ideal for expanding on symbols)Future plans
I intend to expand support beyond files and symbols to URLs and possibly help tags. I am very keen to be able to send over a curated list of git commits with changes, so the LLM has context around how changes are made to projects. Alongside building a tool to send over the full project structure.
Conclusion
As always, thanks for the consistently great ideas and support on the plugin.
Beta Was this translation helpful? Give feedback.
All reactions