[Feature] Add terminals as AI context
- Press
Cmd+Shift+Pin Void, and typeHelp: About. Please paste the information here. Also let us know any other relevant details, like the model and provider you're using if applicable.
VSCode Version: 1.99.30031
Void Version: 1.3.7
Commit: 4b86bfa184b176c26649d77fbbe30026de0c3e81
Date: 2025-05-13T03:21:18.587Z
Electron: 34.3.2
ElectronBuildId: undefined
Chromium: 132.0.6834.210
Node.js: 20.18.3
V8: 13.2.152.41-electron.0
OS: Darwin arm64 24.3.0
- Describe the issue/feature here!
Cursor has a feature where you can add an existing terminal to chat context:
This is useful because it gives the AI context of terminal output. Without this feature you must copy-paste the terminal output yourself.
While Cursor does offer this feature, it has some quirks:
- Adding a terminal to context cannot be done with dropdown menu
- Adding a terminal via @ gives multiple shell results when there isn't more than one
- Shells hang when they shouldn't (as if they're OOM)
- Run noticeably slower than native
- Do not auto-expand and there is no button to adjust/fix
- Regularly have to quit Cursor because the shells pile up and eat all host memory
It's not clear whether these are quirks that bubble up from VSCode, but it would be a significant improvement to address them.
Void already has a terminalToolService with a readTerminal function that is useful (per @andrewpareles).
I would like to implement this feature! This is how I'm thinking about an implementation:
Lifecycle Management:
- Track terminal status (open/close) carefully
- Correctly clean up terminals to be cognizant of memory
Context Integration:
- Integrate terminal output into the AI pipeline
- Add metadata, such as terminal ID, timestamps, and environment details, to each context entry
- Ensure that the AI context can accept the output in chunks
- Potentially integrate some logic that appends or merges terminal output into the existing context for subsequent queries
UI Trigger:
- In context selection dropdown (Type
@in chat), add a new category for "Terminals", which lists the active terminals in the coding session - Once added, the name of the terminal shows in the selected context area of the chat
- Perhaps warn if output includes sensitive patterns
Performance:
- Lazy loading or pagination to improve performance with large terminal outputs (
xterm.getBufferReverseIterator()is possibly all we need) - Implementation is mindful that overloading the AI with excessive or irrelevant terminal output can dilute its effectiveness
- Potentially support diffing new terminal output vs. last injected
I'm brand new to this codebase. I encourage anyone to give me pointers 🙂
Sounds good, let me know if I can answer any questions.
Just to give you an idea of the state we're tracking - I think we have a complete state of whether a terminal is open/closed. For terminals that Void Agent opens, we're tracking the this inpersistentTerminalInstanceOfId and the other object, and for terminals Void Agent didn't open, we can just list terminals like we do in that file.
I've been playing around and discovered two things:
- In
terminalToolService.tsterminals created by Void are stored in thetemporaryTerminalInstanceOfIdvariable:
However, persistent terminals (not created by Void chat) are not currently tracked in persistentTerminalInstanceOfId
- Memory leak after persistent terminal creation in
/src/vs/workbench:
An official fix for this appears to be on the May 2025 roadmap over at VSCode. I think they plan to fix this at a lower-level (lifecycle management) than I did so we can just adopt that patch later. For now consider my fix commit a stopgap: https://github.com/voideditor/void/commit/784180c13734e04aac7689e6ab8648a8575fc92f
Nothing crazy just thought I'd keep you in the loop. Getting persistent terminal tracking going appears to be no problem so I'll use the code that's there and link it up 👍
Interesting, thanks for reporting these. Can definitely improve this and make some fixes
+1