cli

package
v1.53.0 Latest Latest
Warning

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

Go to latest
Published: Apr 28, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateUserMessageWithAttachment

func CreateUserMessageWithAttachment(userContent, attachmentPath string) (*session.Message, string)

CreateUserMessageWithAttachment creates a user message with optional file attachment. Text files are inlined directly as text content for cross-provider compatibility. Binary files (images, PDFs) are stored as file references for provider-specific upload.

Returns the prepared session.Message and the absolute path of the file that was actually attached. The returned path is empty when no attachment was produced (no path supplied, file unreadable, type unsupported, file too large to inline, etc.). Callers should record successful attachments via session.Session.AddAttachedFile so sub-agents inherit the file context.

func ParseAttachCommand

func ParseAttachCommand(userInput string) (messageText, attachPath string)

ParseAttachCommand parses user input for /attach commands Returns the message text (with /attach commands removed) and the attachment path

func PrepareUserMessage

func PrepareUserMessage(ctx context.Context, rt runtime.Runtime, userInput, globalAttachPath string) (*session.Message, string)

PrepareUserMessage resolves commands, parses /attach directives, and creates a user message with optional image attachment. This is the common flow for both TUI and CLI modes.

Parameters:

  • ctx: context for command resolution
  • rt: runtime for command resolution
  • userInput: the raw user input (may contain /commands and /attach directives)
  • globalAttachPath: attachment path from --attach flag (can be empty)

Returns the prepared session.Message ready to be added to the session, plus the absolute path of the file that was actually attached (empty when no attachment was used). Callers should pass that path to session.Session.AddAttachedFile so sub-agents inherit the file context.

func Run

func Run(ctx context.Context, out *Printer, cfg Config, rt runtime.Runtime, sess *session.Session, userMessages []string) error

Run executes an agent in non-TUI mode, handling user input and runtime events. userMessages contains the user messages to send. If a single message is "-", input is read from stdin. If empty, an interactive prompt loop is started.

Types

type Config

type Config struct {
	AppName        string
	AttachmentPath string
	AutoApprove    bool
	HideToolCalls  bool
	OutputJSON     bool
}

Config holds configuration for running an agent in CLI mode

type ConfirmationResult

type ConfirmationResult string

ConfirmationResult represents the result of a user confirmation prompt

const (
	ConfirmationApprove        ConfirmationResult = "approve"
	ConfirmationApproveSession ConfirmationResult = "approve_session"
	ConfirmationReject         ConfirmationResult = "reject"
	ConfirmationAbort          ConfirmationResult = "abort"
)

type Printer

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

func NewPrinter

func NewPrinter(out io.Writer) *Printer

func (*Printer) Print

func (p *Printer) Print(a ...any)

func (*Printer) PrintAgentName

func (p *Printer) PrintAgentName(agentName string)

PrintAgentName prints the agent name header

func (*Printer) PrintError

func (p *Printer) PrintError(err error)

PrintError prints an error message

func (*Printer) PrintToolCall

func (p *Printer) PrintToolCall(toolCall tools.ToolCall)

PrintToolCall prints a tool call

func (*Printer) PrintToolCallResponse

func (p *Printer) PrintToolCallResponse(name, response string)

PrintToolCallResponse prints a tool call response

func (*Printer) PrintToolCallWithConfirmation

func (p *Printer) PrintToolCallWithConfirmation(ctx context.Context, toolCall tools.ToolCall, rd io.Reader) ConfirmationResult

PrintToolCallWithConfirmation prints a tool call and prompts for confirmation

func (*Printer) PrintWelcomeMessage

func (p *Printer) PrintWelcomeMessage(appName string)

PrintWelcomeMessage prints the welcome message

func (*Printer) Printf

func (p *Printer) Printf(format string, a ...any)

func (*Printer) Println

func (p *Printer) Println(a ...any)

func (*Printer) PromptMaxIterationsContinue

func (p *Printer) PromptMaxIterationsContinue(ctx context.Context, maxIterations int) ConfirmationResult

PromptMaxIterationsContinue prompts the user to continue after max iterations

func (*Printer) PromptOAuthAuthorization

func (p *Printer) PromptOAuthAuthorization(ctx context.Context, serverURL string) ConfirmationResult

PromptOAuthAuthorization prompts the user for OAuth authorization

type RuntimeError

type RuntimeError struct {
	Err error
}

RuntimeError wraps runtime errors to distinguish them from usage errors

func (RuntimeError) Error

func (e RuntimeError) Error() string

func (RuntimeError) Unwrap

func (e RuntimeError) Unwrap() error

Jump to

Keyboard shortcuts

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