-
Notifications
You must be signed in to change notification settings - Fork 39
feat(cli): Interactive review for RR. #3317
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
c-r33d
merged 4 commits into
interactive-resolution
from
interactive-resolution-prompter
Apr 20, 2026
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
124 changes: 124 additions & 0 deletions
124
otdfctl/migrations/namespacedpolicy/interactive_prompt.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| package namespacedpolicy | ||
|
|
||
| import ( | ||
| "context" | ||
| "errors" | ||
| "strings" | ||
|
|
||
| "github.com/charmbracelet/huh" | ||
| ) | ||
|
|
||
| var ErrInteractiveReviewAborted = errors.New("interactive review aborted by user") | ||
|
|
||
| // ConfirmPrompt is a generic confirmation prompt for planner-owned review flows. | ||
| type ConfirmPrompt struct { | ||
| Title string | ||
| Description []string | ||
| ConfirmLabel string | ||
| CancelLabel string | ||
| } | ||
|
|
||
| // PromptOption is one selectable value in a generic interactive prompt. | ||
| type PromptOption struct { | ||
| Label string | ||
| Value string | ||
| Description string | ||
| } | ||
|
|
||
| // SelectPrompt is a generic single-select prompt for planner-owned review flows. | ||
| type SelectPrompt struct { | ||
| Title string | ||
| Description []string | ||
| Options []PromptOption | ||
| } | ||
|
|
||
| // InteractivePrompter abstracts the concrete prompt implementation so review | ||
| // orchestration stays planner-owned and testable. | ||
| type InteractivePrompter interface { | ||
| Confirm(context.Context, ConfirmPrompt) error | ||
| Select(context.Context, SelectPrompt) (string, error) | ||
| } | ||
|
|
||
| // HuhPrompter implements InteractivePrompter using charmbracelet/huh forms. | ||
| type HuhPrompter struct{} | ||
|
|
||
| func (p *HuhPrompter) Confirm(ctx context.Context, prompt ConfirmPrompt) error { | ||
| confirmLabel := strings.TrimSpace(prompt.ConfirmLabel) | ||
| if confirmLabel == "" { | ||
| confirmLabel = "Continue" | ||
| } | ||
|
|
||
| cancelLabel := strings.TrimSpace(prompt.CancelLabel) | ||
| if cancelLabel == "" { | ||
| cancelLabel = "Abort" | ||
| } | ||
|
|
||
| var choice bool | ||
| form := huh.NewForm( | ||
| huh.NewGroup( | ||
| huh.NewConfirm(). | ||
| Title(strings.TrimSpace(prompt.Title)). | ||
| Description(promptDescription(prompt.Description)). | ||
| Affirmative(confirmLabel). | ||
| Negative(cancelLabel). | ||
| Value(&choice), | ||
| ), | ||
| ) | ||
|
|
||
| if err := form.RunWithContext(ctx); err != nil { | ||
| if errors.Is(err, huh.ErrUserAborted) { | ||
| return ErrInteractiveReviewAborted | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| if !choice { | ||
| return ErrInteractiveReviewAborted | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
|
|
||
| func (p *HuhPrompter) Select(ctx context.Context, prompt SelectPrompt) (string, error) { | ||
| options := make([]huh.Option[string], 0, len(prompt.Options)) | ||
| for _, option := range prompt.Options { | ||
| label := option.Label | ||
| if description := strings.TrimSpace(option.Description); description != "" { | ||
| label += " - " + description | ||
| } | ||
| options = append(options, huh.NewOption(label, option.Value)) | ||
| } | ||
|
|
||
| var choice string | ||
| form := huh.NewForm( | ||
| huh.NewGroup( | ||
| huh.NewSelect[string](). | ||
| Title(strings.TrimSpace(prompt.Title)). | ||
| Description(promptDescription(prompt.Description)). | ||
| Options(options...). | ||
| Value(&choice), | ||
| ), | ||
| ) | ||
|
|
||
| if err := form.RunWithContext(ctx); err != nil { | ||
| if errors.Is(err, huh.ErrUserAborted) { | ||
| return "", ErrInteractiveReviewAborted | ||
| } | ||
| return "", err | ||
| } | ||
|
|
||
| return choice, nil | ||
| } | ||
|
|
||
| func promptDescription(description []string) string { | ||
| lines := make([]string, 0, len(description)) | ||
| for _, line := range description { | ||
| line = strings.TrimSpace(line) | ||
| if line == "" { | ||
| continue | ||
| } | ||
| lines = append(lines, line) | ||
| } | ||
|
|
||
| return strings.Join(lines, "\n") | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.