GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Update the `ICommandPredictor` to provide more feedback and also make feedback easier to be corelated by daxian-dbw · Pull Request #14649 · PowerShell/PowerShell

Conversation

@daxian-dbw

@daxian-dbw Dongbo Wang (daxian-dbw) commented Jan 21, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

PR Summary

Update the ICommandPredictor interface APIs to allow a predictor to get feedback about what suggestions from it were displayed to the user, and also make it easier for a predictor to corelate feedback events.

  1. Add ICommandPredictor.OnSuggestionDisplayed, to let a predictor know what results were displayed to the user when rendering the results: void OnSuggestionDisplayed(uint session, int countOrIndex);

    • The countOrIndex parameter can help a predictor to tell if the display was in ListView or InlineView:
      • When the value is > 0, it's the number of displayed suggestions from the list returned in , starting from the index 0. This indicates the ListView is in use.
      • When the value is <= 0, it means a single suggestion from the list got displayed, and the index is the absolute value. This indicates the InlineView is in use.
  2. Add clientId and session parameters to the existing interface APIs. The clientId parameter helps a predictor to know what host client is calling it (PSReadLine only today, but it could be the PS VSCode extension some day in future); the session parameter helps a predictor to corelate feedback events.

    • GetSuggestion and StartEarlyProcessing both take a string parameter clientId, so it knows the client that makes the call
    • GetSuggestion returns a uint type session value, along with the list of suggestion entries it provides.
    • OnSuggestionDisplayed and OnSuggestionAccepted both take a uint parameter session, which indicates where the displayed or accepted suggestions were from.

/cc kceiw

This PR also includes a few changes to the scripts that generate PowerShell SDK NuGet packages, to make it works properly with the other changes from this PR, and also make NuGet packages include the XML document files.

PR Checklist

  • PR has a meaningful title
    • Use the present tense and imperative mood when describing your changes
  • Summarized changes
  • Make sure all .h, .cpp, .cs, .ps1 and .psm1 files have the correct copyright header
  • This PR is ready to merge and is not Work in Progress.
    • If the PR is work in progress, please add the prefix WIP: or [ WIP ] to the beginning of the title (the WIP bot will keep its status check at Pending while the prefix is present) and remove the prefix when the PR is ready.
  • Breaking changes
    • None
    • OR
    • Experimental feature(s) needed
      • Experimental feature name(s): PSSubsystemPluginModel
  • User-facing changes
    • Not Applicable
    • OR
    • Documentation needed
      • Issue filed: No need to update PowerShell docs. It affect the XML documentation only.
  • Testing - New and feature
    • N/A or can only be tested interactively
    • OR
    • Make sure you've added a new test if existing tests do not effectively test the code changed
  • Tooling
    • I have considered the user experience from a tooling perspective and don't believe tooling will be impacted.
    • OR
    • I have considered the user experience from a tooling perspective and enumerated concerns in the summary. This may include:
      • Impact on PowerShell Editor Services which is used in the PowerShell extension for VSCode (which runs in a different PS Host).
      • Impact on Completions (both in the console and in editors) - one of PowerShell's most powerful features.
      • Impact on PSScriptAnalyzer (which provides linting & formatting in the editor extensions).
      • Impact on EditorSyntax (which provides syntax highlighting with in VSCode, GitHub, and many other editors).

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Dongbo Wang (daxian-dbw) added 4 commits January 11, 2021 21:24
@daxian-dbw
Update the ICommandPredictor interface with API changes
3d2cbce
@daxian-dbw
Use 'uint' type for the mini-session id
589666e
@daxian-dbw
Minor update
203683e
@daxian-dbw
Fix script that create new NuGet package
4eb7aac
@ghost ghost assigned Andrew (anmenaga) Jan 21, 2021
@daxian-dbw
Address CodeFactor issues
4500afb
@daxian-dbw
Dongbo Wang (daxian-dbw) force-pushed the predict branch from ff8a72c to 4500afb Compare January 22, 2021 01:35
@daxian-dbw
Update tests and also add more tests
e3eb21d
@daxian-dbw Dongbo Wang (daxian-dbw) changed the title Predict Update the ICommandPredictor to provide more feedback and also make feedback easier to be corelated Jan 22, 2021
@daxian-dbw
Address codefactor issues
bea03e3
@daxian-dbw
Dongbo Wang (daxian-dbw) force-pushed the predict branch from 351a118 to bea03e3 Compare January 22, 2021 18:52
iSazonov
Ilya (iSazonov) reviewed Jan 25, 2021
View reviewed changes
Comment thread src/System.Management.Automation/engine/Subsystem/CommandPrediction/ICommandPredictor.cs Outdated
Comment on lines +64 to +71
void OnSuggestionDisplayed(uint session, int countOrIndex);

/// <summary>
/// The suggestion provided by the predictor was accepted.
/// </summary>
/// <param name="session">Represents the mini-session where the accepted suggestion came from.</param>
/// <param name="acceptedSuggestion">The accepted suggestion text.</param>
void OnSuggestionAccepted(uint session, string acceptedSuggestion);

@iSazonov Ilya (iSazonov) Jan 25, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We could merge both methods if they are always used together.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 26, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

They are not used together. OnSuggestionDisplayed will be fired way more than OnSuggestionAccepted.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Jan 26, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

My thoughts are if we get 100 suggestions we could weight all 100 (including displayed and accepted ones) and return the result to the prediction service so that it could make more better analyze. So users could prefer a case-sensitive selection or use other sources for selection (local configs, history or other prediction services) to inform the prediction service.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 26, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

My thoughts are if we get 100 suggestions we could weight all 100 (including displayed and accepted ones) and return the result to the prediction service so that it could make more better analyze.

It's pretty common that we get suggestions from a predictor but user doesn't accept anything, so it's not clear to me how to always include "displayed and accepted ones" in a feedback.

After this change, "OnSuggestionDisplayed" event will be fired very often. I very much want to reduce it ..., so any ideas are very welcome. Can you maybe elaborate your thoughts more?

So users could prefer a case-sensitive selection or use other sources for selection (local configs, history or other prediction services) to inform the prediction service.

Not sure I understand what you mean, it would be nice if you can clarify more. Basically, we try to avoid sending more user local infor to a predictor than really needed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@iSazonov Ilya (iSazonov) Jan 27, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

We've heard more than once that users want to restore a PowerShell session after a restart. For this service it might be useful too.

My thoughts may be vague, but I believe that if a service does not store permanently the (session) state, then this state should be stored locally.

What is a session data? (1) Personal sensitive user data (stored only locally), (2) service data. Service data may be (1) complex data structure (like subset of ML model), (2) simple tips (references on internal service models)

I think that if user data should not be stored on the service, then there might be the following options:

  1. No data is stored locally between sessions
  2. All session data is stored locally (including model)
  3. All sensitive data is stored locally (including service tips).

Also I think there are many claims about sensing user data to Cloud. The service could be data agnostic and gets encrypted data.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@anmenaga Andrew (anmenaga) Feb 4, 2021

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This feels like a design proposal for a separate feature "restore a PowerShell session after a restart" :)

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/System.Management.Automation/engine/Subsystem/CommandPrediction/CommandPrediction.cs Outdated
/// <summary>
/// Gets the mini-session id that represents a specific invocation to the <see cref="ICommandPredictor.GetSuggestion"/> API of the predictor.
/// </summary>
public uint Session { get; }

@iSazonov Ilya (iSazonov) Jan 25, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Why uint? Maybe Guid to be globally independent?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Jan 26, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The session is always under a context, for example, a period of time when a predictor module is loaded and used, a Runspace instance id where the module is loaded. That context can be uniquely identified, so I think there is no need for the mini-session to be globally unique.

I use uint only because it provides a large space and easy to increment to get a new mini-session id. Azure PowerShell team is using this prediction API for the Az Predictor. I'm waiting on the their feedback on this.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 1, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The Az.Predictor team has confirmed that uint works fine, becuase they already have other context information that is uniquely identifiable. /cc kceiw

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

iSazonov reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Dongbo Wang (daxian-dbw) added 2 commits January 28, 2021 13:05
@daxian-dbw
Pass 'ClientId' to 'OnSuggestionDisplay' and 'OnSuggestionAccepted' a…
6bf5817
…nd also make 'Session' use 'uint?' type
@daxian-dbw
Add the API xml document files to the generated NuGet packages
0b7e42d
@daxian-dbw
Dongbo Wang (daxian-dbw) marked this pull request as ready for review February 1, 2021 19:13
@daxian-dbw
Dongbo Wang (daxian-dbw) requested review from Travis Plunk (TravisEz13), Aditya Patwardhan (adityapatwardhan) and Andrew (anmenaga) as code owners February 1, 2021 19:13
@daxian-dbw
Dongbo Wang (daxian-dbw) requested a review from Rob Holt (rjmholt) February 1, 2021 19:17
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Feb 1, 2021

Copy link
Copy Markdown
Member Author

Rob Holt (@rjmholt) and Andrew (@anmenaga) this PR is ready, please help review it, thank!
kceiw I will appreciate it if you can review this PR as well.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

powercode
Staffan Gustafsson (powercode) reviewed Feb 1, 2021
View reviewed changes
Comment thread src/System.Management.Automation/engine/Utils.cs
}
}

internal static void NotNullOrEmpty(ICollection value, string paramName)

@powercode Staffan Gustafsson (powercode) Feb 1, 2021

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Perhaps use [CallerArgumentExpression("value")] ?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 4, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It's not implemented yet, right? See the proposal doc and the open issue: dotnet/csharplang#287

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@powercode Staffan Gustafsson (powercode) Feb 4, 2021 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Collaborator

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

You're correct! I was misled by the docs. I have used CallerMemberName and read the documentation for CAE and just assumed it worked as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

daxian-dbw reacted with laugh emoji
All reactions
  • 😄 1 reaction
@anmenaga Andrew (anmenaga) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label Feb 4, 2021
anmenaga
Andrew (anmenaga) approved these changes Feb 4, 2021
View reviewed changes

@anmenaga Andrew (anmenaga) left a comment

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Looks fine.
Please file a doc issue and link it in "Documentation needed"/"Issue filed:" in PR Checklist; thank you.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tools/packaging/packaging.psm1
Write-Log "Reference assembly '$assemblyName.dll' built and copied to $RefAssemblyDestinationPath"

Copy-Item $dllXmlDoc $RefAssemblyDestinationPath -Force
Write-Log "Xml document '$assemblyName.xml' copied to $RefAssemblyDestinationPath"

@anmenaga Andrew (anmenaga) Feb 4, 2021

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

... make NuGet packages include the XML document files.
This is not really related to prediction APIs. Could have been a separate PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 4, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Not directly related, but sort of. The script needs to be updated after the changes in API because new attributes are used which need to be scrubbed when generating the reference assembly, so I have to update the packaging scripts. While doing so, I found the XML docs are missing when using our NuGet packages in VS Code or Visual Studio, and thus I fix that too.
Since we need to include part of the fixes in packaging.psm1 anyways, I prefer to keep all changes in this PR.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread tools/packaging/packaging.psm1
@{
ApplyTo = @("System.Management.Automation")
Pattern = "[System.Runtime.CompilerServices.CompilerGeneratedAttribute, System.Runtime.CompilerServices.IsReadOnlyAttribute]"
Replacement = "/* [System.Runtime.CompilerServices.CompilerGeneratedAttribute, System.Runtime.CompilerServices.IsReadOnlyAttribute] */ "

@anmenaga Andrew (anmenaga) Feb 4, 2021

Copy link
Copy Markdown

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Can you please explain why this is needed?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@daxian-dbw Dongbo Wang (daxian-dbw) Feb 4, 2021

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

The CompilerGeneratedAttribute and IsReadOnlyAttribute are added by the C# compiler to the readonly members of a struct in the generated IL. Those attributes can only be used by the C# compiler and thus will result in complication error when they are in the source code. Therefore, we need to scrub them out before compiling to get our reference assembly.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@daxian-dbw

Dongbo Wang (daxian-dbw) commented Feb 4, 2021 •
edited by unfurl-links Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

Andrew (@anmenaga) Thanks for the review!
There is no need to update PowerShell docs. The PSSubsystemPluginModel experimental feature is only mentioned here: https://docs.microsoft.com/en-us/powershell/scripting/learn/experimental-features?view=powershell-7.1#pssubsystempluginmodel, and it doesn't talk about specific APIs. We only need to update the XML document for the APIs, which is done by the updates to packaging.psm1.

Using Experimental Features in PowerShell - PowerShell
Lists the currently available experimental features and how to use them.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@anmenaga
Andrew (anmenaga) merged commit e803d3b into PowerShell:master Feb 4, 2021
@daxian-dbw
Dongbo Wang (daxian-dbw) deleted the predict branch February 5, 2021 01:13
@iSazonov Ilya (iSazonov) added this to the 7.2.0-preview.3 milestone Feb 5, 2021
@ghost

Deleted user (ghost) commented Feb 12, 2021

Copy link
Copy Markdown

🎉v7.2.0-preview.3 has been released which incorporates this pull request.:tada:

Handy links:

  • Release Notes
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@andrew-boyarshin Andrew Boyarshin (andrew-boyarshin) mentioned this pull request Feb 17, 2021
PSReadLine doesn't work on 7.2.0-preview.3 PowerShell/PSReadLine#2221
Closed
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
@daxian-dbw
Update the ICommandPredictor to provide more feedback and also make…
66be62e
… feedback easier to be corelated (PowerShell#14649)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@iSazonov Ilya (iSazonov) iSazonov left review comments
@adityapatwardhan Aditya Patwardhan (adityapatwardhan) Awaiting requested review from adityapatwardhan
@TravisEz13 Travis Plunk (TravisEz13) Awaiting requested review from TravisEz13
@rjmholt Rob Holt (rjmholt) Awaiting requested review from rjmholt
+2 more reviewers
@powercode Staffan Gustafsson (powercode) powercode left review comments
@anmenaga Andrew (anmenaga) anmenaga approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@anmenaga Andrew (anmenaga)

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log

Projects

None yet

Milestone

7.2.0-preview.3

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@daxian-dbw @powercode @anmenaga @iSazonov
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.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.