Support posting code from the sidecar AIShell to PowerShell with Invoke-AIShell -PostCode
#361
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.
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.-PostCode
,-CopyCode
, and-Exit
parameters toInvoke-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.CodePost
message comes in, theAIShell
module will check ifPSReadLine
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 theOnIdle
event, and the event handler will insert the posted code when PowerShell becomes idle.