communicate

package
v0.1.155 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 24, 2026 License: MIT Imports: 6 Imported by: 4

README

Communication between CLI and Plugin

Bidirectional gRPC streaming for interactive Q&A.

Flow
  1. CLI opens a Communicate bidirectional stream to the plugin
  2. Plugin sends Question messages (confirm, input, selection, choice)
  3. CLI answers each question via the AnswerProvider interface
  4. CLI sends Answer messages back on the stream
  5. Plugin stores answers and closes the stream when done
Plugin side
func (s *Builder) Communicate(stream builderv0.Builder_CommunicateServer) error {
    asker := communicate.NewQuestionAsker(stream)
    answers, err := asker.RunSequence(s.Options())
    s.answers = answers
    return err
}
CLI side
stream, _ := instance.Builder.Communicate(ctx)
communicate.Do(ctx, stream, answerProvider)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Choice added in v0.1.155

func Choice(answers map[string]*agentv0.Answer, stage string) (*agentv0.ChoiceAnswer, error)

func Confirm added in v0.1.155

func Confirm(answers map[string]*agentv0.Answer, stage string) (bool, error)

func Display added in v0.0.51

func Display(msg *agentv0.Message, data map[string]string) *agentv0.Question

func Do added in v0.0.51

Do drives a bidirectional Communicate stream from the CLI side. It reads Questions from the stream, passes them to the AnswerProvider, and sends Answers back until the stream closes.

func GetDefaultConfirm added in v0.1.89

func GetDefaultConfirm(options []*agentv0.Question, name string) (bool, error)

func GetDefaultStringInput added in v0.1.89

func GetDefaultStringInput(options []*agentv0.Question, name string) (string, error)

func InputInt added in v0.1.155

func InputInt(answers map[string]*agentv0.Answer, stage string) (int, error)

func InputString added in v0.1.155

func InputString(answers map[string]*agentv0.Answer, stage string) (string, error)

func NewChoice added in v0.0.51

func NewChoice(msg *agentv0.Message, options ...*agentv0.Message) *agentv0.Question

func NewConfirm added in v0.0.51

func NewConfirm(msg *agentv0.Message, defaultConfirm bool) *agentv0.Question

func NewIntInput added in v0.1.33

func NewIntInput(msg *agentv0.Message, defaultValue int) *agentv0.Question

func NewSelection added in v0.0.51

func NewSelection(msg *agentv0.Message, options ...*agentv0.Message) *agentv0.Question

func NewStringInput added in v0.0.51

func NewStringInput(msg *agentv0.Message, defaultValue string) *agentv0.Question

func Selection added in v0.1.155

func Selection(answers map[string]*agentv0.Answer, stage string) (*agentv0.SelectionAnswer, error)

Types

type AnswerProvider added in v0.0.51

type AnswerProvider interface {
	Answer(ctx context.Context, question *agentv0.Question) (*agentv0.Answer, error)
}

AnswerProvider answers interactive questions from a plugin. The CLI implements this (e.g. terminal prompts, defaults).

type QuestionAsker added in v0.1.155

type QuestionAsker struct {
	// contains filtered or unexported fields
}

QuestionAsker is implemented by plugins to ask questions during Create/Sync. It sends Questions and receives Answers on a bidi stream.

func NewQuestionAsker added in v0.1.155

NewQuestionAsker wraps a bidi stream for the plugin side.

func (*QuestionAsker) Ask added in v0.1.155

func (qa *QuestionAsker) Ask(question *agentv0.Question) (*agentv0.Answer, error)

Ask sends a question to the CLI and waits for the answer.

func (*QuestionAsker) RunSequence added in v0.1.155

func (qa *QuestionAsker) RunSequence(questions []*agentv0.Question) (map[string]*agentv0.Answer, error)

RunSequence asks a sequence of questions and returns all answers keyed by question name.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL