Skip to content

Support posting code from the sidecar AIShell to PowerShell with Invoke-AIShell -PostCode #361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025

Conversation

daxian-dbw
Copy link
Member

PR Summary

By leveraging the fix in PowerShell/PSReadLine#4442, which handles buffer changes made by a handler of the OnIdle event, now we are able to post code to PowerShell from the sidecar AIShell even when PowerShell is busy running a command. The posted code will be inserted into prompt after PowerShell finishes running the current command.

  • Add -PostCode, -CopyCode, and -Exit parameters to Invoke-AIShell in their separate parameter sets. So, a user don't have to leave the PowerShell session they are working in -- they can send query, copy or post code from the AI response, and exit the sidecar AIShell directly from the PowerShell session.
  • When the CodePost message comes in, the AIShell module will check if PSReadLine is active (whether PSReadLine is running to process user input). If it's active, we revert the current line and insert the posted code; if it's not, then we register a subscriber to the OnIdle event, and the event handler will insert the posted code when PowerShell becomes idle.

@daxian-dbw daxian-dbw requested a review from Copilot April 2, 2025 00:36
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds new parameter sets to the Invoke-AIShell command to enable posting, copying code, and exiting directly from the AIShell sidecar, and updates the channel to process posted code through the PSReadLine idle event.

  • Added new parameter sets (PostCode, CopyCode, Exit) to better handle different code actions.
  • Updated the OnPostCode logic in Channel.cs to use the idle event for code insertion when PowerShell is busy, and introduced a new record type for pending code data.

Reviewed Changes

Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.

File Description
shell/AIShell.Integration/Commands/InvokeAishCommand.cs Added new parameter sets and corresponding logic for handling code posting, copying, and exit operations.
shell/AIShell.Integration/Channel.cs Updated PostCode handling with an event-driven mechanism via OnIdleHandler and introduced thread-local storage for pending post code data.
Files not reviewed (2)
  • shell/AIShell.Integration/AIShell.psd1: Language not supported
  • shell/AIShell.Integration/AIShell.psm1: Language not supported

@daxian-dbw daxian-dbw merged commit 8367575 into PowerShell:main Apr 2, 2025
7 checks passed
@daxian-dbw daxian-dbw deleted the post branch April 2, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants