Add session history / new / delete toolbar to embedded terminal (#9)#10
Add session history / new / delete toolbar to embedded terminal (#9)#10bommerts wants to merge 3 commits into
Conversation
Adds a toolbar to the embedded Copilot CLI tool window with two buttons: - View Session History — VS-themed picker filtered to the current workspace that resumes a previous Copilot CLI session via `copilot --resume=<id>`. Reads ~/.copilot/session-store.db in read-only mode (Microsoft.Data.Sqlite). - New Session — restarts the terminal with a fresh `copilot`. Buttons use KnownMonikers.History and KnownMonikers.NewItem via `IconIsMoniker` so they pick up the active VS theme. Both commands are disabled when no solution is open. Hardening: - Session ids passed to `--resume=` are validated against a strict UUID regex before being interpolated into the cmd.exe command line. - Workspace path matching is separator-aware in both SQL (`LIKE workspace + sep + '%'`) and C# to avoid sibling overmatch (`C:\repo` matching `C:\repo-old`). - `TerminalProcess.IsRunning` now returns false after the hosted CLI exits — fixes the Enter-to-restart UX. - `TerminalSessionService` exposes explicit `RestartFresh` / `RestartResuming` / `RestartPreservingMode` methods replacing the previous tri-state `RestartSession` parameters. Native `e_sqlite3.dll` (win-x64 + win-arm64) is bundled in the VSIX via a `BundleSqliteInVsix` MSBuild target running after the VSSDK strip step. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Adds a third toolbar button to the embedded Copilot CLI tool window: - Delete Current Thread (KnownMonikers.DeleteListItem) — stops the running CLI, transactionally deletes the current session and all dependent rows (turns, session_files, session_refs, checkpoints, search_index FTS entries) from session-store.db, then restarts with a fresh session. Confirms before deleting and shows the first 8 chars of the session id so the user can sanity-check. The current session id is resolved from TerminalSessionService.LastResumeSessionId when known (we used --resume=<id>), otherwise from the most-recently-updated session for the workspace in session-store.db. Switches the toolbar from VS's native command toolbar to a custom WPF toolbar hosted inside TerminalToolWindowControl. VS tool window toolbars are left-aligned only; the WPF toolbar lets the buttons sit top-right, matching VS Code's terminal placement. WPF buttons invoke handler methods on the package via Action delegates exposed through VsServices.Instance. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Thank you @bommerts for this contribution. I get the impression that the toolbar is causing resize synchronization issues on the device; for me, it’s consistently broken. I think adding XAML components prevents the system from correctly targeting the right control to force a refresh. I’ll also look into whether it’s possible to add the icons to the toolbar frame instead of adding a bar that ultimately takes up space. Finally, there are rendering issues related to how VS handles themes. That’s why I’m always hesitant whenever we start introducing UI elements. It takes a lot of code and effort to meet VS’s constraints. |
| // Polyfills for C# language features that target newer BCLs but only require | ||
| // internal sentinel types. .NET Framework 4.7.2 doesn't ship these — they're | ||
| // declared here so we can use `record`, `init`, and `required` in this assembly. | ||
| namespace System.Runtime.CompilerServices |
There was a problem hiding this comment.
uneeded polyfills, we can use regular structs instead of records
| @@ -0,0 +1,16 @@ | |||
| using System.Text.RegularExpressions; | |||
|
|
|||
| namespace CopilotCliIde; | |||
There was a problem hiding this comment.
Guid.TryParse is not usable here ?
|
|
||
| namespace CopilotCliIde; | ||
|
|
||
| // VS-themed picker for resuming a previous Copilot CLI session. |
There was a problem hiding this comment.
the AI is lying :p it is not themed at all. VS is now providing themed styles for all controls but you have to wire stuff a bit. With my black-theme the rendering is a bit strange.
| Content = _termControl; | ||
|
|
||
| // Attach to session early — Resize may fire before OnLoaded | ||
| // Two-row layout: a thin right-aligned toolbar above the terminal control. |
There was a problem hiding this comment.
this layout brakes the terminal rendering.
Gotcha. I was wondering the same. I'm also curious when the VS team will include GitHub Copilot CLI native to VS because it is so much better than GitHub Copilot Chat, effectively removing the need for this repo. Or maybe they'll merge this repo into VS :) Thanks for the detailed feedback above. I'll take a pass at fixing these issues. |
- Drop Polyfills.cs; convert SessionInfo / SessionQueryResult to plain
readonly structs and Row to a regular class (no records, no required/init).
- Replace SessionId regex with Guid.TryParseExact ("D" format).
- Revert custom WPF toolbar; restore the native VSCT ToolWindowToolbar with
the three buttons. The WPF Grid wrapper above the native TerminalControl
HWND host caused resize-sync issues for the maintainer; the native toolbar
avoids that and matches every other VS tool window's left-aligned
convention (Solution Explorer, Output, Error List, etc.).
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Pushed 6b3e1ee addressing all four review comments:
|
Closes #9.
Adds a toolbar to the embedded Copilot CLI tool window with three buttons, right-aligned at the top:
KnownMonikers.History) — opens a VS-themed picker filtered to the current workspace, lets the user pick a previous Copilot CLI session, and resumes it viacopilot --resume=<id>.KnownMonikers.NewItem) — restarts the terminal with a freshcopilot.KnownMonikers.DeleteListItem) — confirms, then transactionally deletes the current chat thread (acrosssessions,turns,session_files,session_refs,checkpoints, and thesearch_indexFTS5 table) and restarts fresh.Implementation notes
~/.copilot/session-store.dbviaMicrosoft.Data.Sqlite(Mode=ReadOnlyfor the picker,Mode=ReadWritefor delete) so it does not contend with the live CLI's WAL writer.e_sqlite3.dllis bundled in the VSIX for bothwin-x64andwin-arm64via an MSBuild target runningAfterTargets="RemoveVSSDKAssemblies".--resume=are validated against a strict UUID regex before being interpolated into thecmd.execommand line (defense against shell injection).LIKE workspace + sep + ''%'') and C# to avoid sibling overmatch (e.g.C:\reposhould not matchC:\repo-old).TerminalSessionServiceexposes explicitRestartFresh/RestartResuming/RestartPreservingModemethods (replaces a brittle tri-stateRestartSessionparameter set).TerminalProcess.IsRunningstayedtrueafter the hosted CLI exited, breaking the Enter-to-restart UX.New dependencies
Microsoft.Data.Sqlite9.0.0SQLitePCLRaw.lib.e_sqlite32.1.10Both target
netstandard2.0and work onnet472.Verification
msbuildclean (0 warnings, 0 errors).--resume=<id>, delete removes the row fromsession-store.dband restarts fresh, both old commands disabled when no solution is open.Per the heads-up posted on issue #9.