Rework AI terminal commands with VS Code-style shell integration#330
Merged
Conversation
Keep AI commands in the real interactive terminal while reporting completion and exit status through inherited pipes. Recover the completion handshake after interactive Ctrl+C and remove prompt-marker parsing from chat output. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Initialize a shell completion function before showing Unix terminals and use short per-terminal sequence IDs so hidden completion calls stay on one terminal row. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Using a fixed path under the shared /tmp allowed another local user to pre-create the directory and tamper with the scripts our shells source (TOCTOU), and blocked script writes for the second user on multi-user systems. Scripts now live in ~/.oneware/shell-integration (0700). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
# Conflicts: # src/OneWare.Chat/Services/AiFunctionProvider.cs # src/OneWare.Essentials/Services/IAiFunctionProvider.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-up to #322. Full rework of how AI terminal commands are tracked, replacing the out-of-band completion channel with VS Code-style shell integration.
Terminal command tracking (OSC 633 shell integration)
The previous approach typed a visible marker command into the shell, suppressed its echo with cursor-erase hacks, and signalled completion through extra pipes/handles — which sometimes leaked the marker into the user-facing terminal and behaved differently across Unix/Windows.
Now, shell startup files install prompt hooks that emit invisible, in-band
OSC 633sequences (C= command started,D;<exit>= command finished with exit code), exactly like VS Code's shell integration:ShellIntegration.cs— generates integration scripts for bash (--init-file), zsh (ZDOTDIR) and PowerShell, sourcing the user's own startup files first. Scripts are written atomically to a per-user directory (~/.oneware/shell-integration,0700).ShellIntegrationParser.cs— chunk-safe streaming parser that stripsOSC 633sequences from pty output and raises typed events; all other escape sequences pass through untouched.TerminalManagerViewModel— captures output strictly between theC/Dmarkers (no prompt drawing, no command echo) with a short grace period so multi-line command blocks complete as one execution.UserInputEchoFilterkeeps echoed keystrokes out of the captured/streamed tool output (visible terminal unaffected).Robustness fixes
exit/crash of the shell no longer hangs pending executions — pty EOF raisesClosed, the real process exit code is captured (waitpidon Unix,Process.ExitCodeon Windows) and reported, and the terminal tab closes automatically.execve.Chat UX
CancellationTokenSource(IAiFunctionProvider.CancelFunction); the model receives a graceful "stopped by user" result instead of the turn failing.IChatServicequeue management (RemoveMostRecentQueuedMessageAsync/ClearQueuedMessagesAsync) wired to the Copilot SDK.Tests
New/rewritten coverage: parser strip/event/chunk-split tests, spawn-config tests per shell, echo-filter tests, and live-bash integration tests (command lifecycle, failing exit codes,
exit 3closing the session with the real exit code, no marker/control-byte leakage). 22 tests passing.Net result: −460 lines while covering more edge cases.
Submodule cleanup: hendrikmennen/VtNetCore.Avalonia#2