Skip to content

feat: implement terminal command AI Variable#17312

Open
Fangoling wants to merge 5 commits intoeclipse-theia:masterfrom
EduIDE:terminal-command-variable
Open

feat: implement terminal command AI Variable#17312
Fangoling wants to merge 5 commits intoeclipse-theia:masterfrom
EduIDE:terminal-command-variable

Conversation

@Fangoling
Copy link
Copy Markdown
Contributor

What it does

This PR builds on top of #16732.
This PR introduces a new AI Variable that allows the user to target a specific command in their last used terminal.

  • the user can specify the command using an index directly or via the arguments picker
  • If no index is provided, the variable defaults to the last executed command

If the experimental command history preference is disabled, this ai variable will return the last 50 lines of the terminal buffer.

ai-variable-terminal-1775517866896.mp4

How to test

  1. Open the Theia Settings
  2. Enable Terminal › Integrated: Enable Command History
  3. Execute some commands in the terminal
  4. Open the AI Chat
  5. Use the #terminalCommand AI Variable in the AI Chat and choose a terminal command via the arguments picker
  6. Prompt the agent to repeat the content of the prompt to verify that the correct command was passed

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

- stores a command and its corresponding output
- a specific command can be adressed via an index or chosen in the arguments picker
- falls back to last executed command when no index is passed
- when command history is disable return the last 50 lines

Signed-off-by: Fangxing Liu <fx.liu@tum.de>
Signed-off-by: Fangxing Liu <fx.liu@tum.de>
Signed-off-by: Fangxing Liu <fx.liu@tum.de>
@Fangoling Fangoling mentioned this pull request Apr 13, 2026
3 tasks
@eneufeld
Copy link
Copy Markdown
Contributor

What is the use case for this, especially with the variable?
Wouldn't it be better to have a toolcall? then I understand that the llm could decide itself that it needs to check a command that ran in the past and its output.

@Fangoling
Copy link
Copy Markdown
Contributor Author

Fangoling commented Apr 13, 2026

What is the use case for this, especially with the variable? Wouldn't it be better to have a toolcall? then I understand that the llm could decide itself that it needs to check a command that ran in the past and its output.

This is a building block for #17308 which adds per-block command actions to the terminal.

The primary use case would be passing the context of a terminal block directly to the ai chat mirroring the functionality of the Ask AI functionality in the ai-editor:

  • the user clicks on a terminal command block and select the 'Ask AI' tool tip
  • after entering a prompt into the window the user, the prompt and terminal context is passed into the ai chat

Currently the terminal variable is passed in as plain text and it would be nice to hide this behind the abstraction of an AI variable. The selection of the terminal command directly in the chat input window is just a nice to have.

The toolcall usecase is also good point, I can create an issue for this.

Copy link
Copy Markdown
Contributor

@eneufeld eneufeld left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me overall and works great.
I left some comment. The missing disposal is the main missing one.

Comment thread packages/ai-terminal/src/browser/ai-terminal-command-block-variable.ts Outdated
Comment thread packages/ai-terminal/src/browser/ai-terminal-command-block-variable.ts Outdated
Comment thread packages/ai-terminal/src/browser/ai-terminal-command-block-variable.ts Outdated
@github-project-automation github-project-automation Bot moved this from Waiting on reviewers to Waiting on author in PR Backlog Apr 17, 2026
…ck variable

- Return undefined instead of an empty string when the terminal buffer is empty (no command history state)
- Replace parseInt with Number(...trim()) for arg parsing and add full index validation (NaN, non-integer, out-of-bounds) to prevent silent
invalid lookups
- Format resolved variable value with markdown headings for clearer AI context
- Normalize whitespace in quick pick descriptions before truncating to avoid multi-line output in the picker
- Fix quickPick.dispose() placement so it always runs on accept (not only on successful selection) and also runs on hide

Signed-off-by: Fangxing Liu <fx.liu@tum.de>
@Fangoling
Copy link
Copy Markdown
Contributor Author

Fangoling commented Apr 23, 2026

I also adjusted the 'prompt' on how the command and output are passed to the terminal. They are now passed in this shape:

### Terminal Command
{command}
### Terminal Output
{output}
```.
And added an warn log for the invalid input branch.

@Fangoling Fangoling requested a review from eneufeld April 23, 2026 16:52
Signed-off-by: Fangxing Liu <fx.liu@tum.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Waiting on author

Development

Successfully merging this pull request may close these issues.

2 participants