repl

package
v0.0.29 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2025 License: MIT Imports: 18 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinThemes = map[string]Theme{
	"default": {
		Name:   "Default",
		Styles: DefaultStyles(),
	},
	"dark": {
		Name: "Dark",
		Styles: Styles{
			Title: lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("15")).
				Background(lipgloss.Color("236")).
				Padding(0, 1),

			Prompt: lipgloss.NewStyle().
				Foreground(lipgloss.Color("11")).
				Bold(true),

			Result: lipgloss.NewStyle().
				Foreground(lipgloss.Color("14")),

			Error: lipgloss.NewStyle().
				Foreground(lipgloss.Color("9")).
				Bold(true),

			Info: lipgloss.NewStyle().
				Foreground(lipgloss.Color("3")).
				Italic(true),

			HelpText: lipgloss.NewStyle().
				Foreground(lipgloss.Color("243")).
				Italic(true),
		},
	},
	"light": {
		Name: "Light",
		Styles: Styles{
			Title: lipgloss.NewStyle().
				Bold(true).
				Foreground(lipgloss.Color("0")).
				Background(lipgloss.Color("252")).
				Padding(0, 1),

			Prompt: lipgloss.NewStyle().
				Foreground(lipgloss.Color("4")).
				Bold(true),

			Result: lipgloss.NewStyle().
				Foreground(lipgloss.Color("6")),

			Error: lipgloss.NewStyle().
				Foreground(lipgloss.Color("1")).
				Bold(true),

			Info: lipgloss.NewStyle().
				Foreground(lipgloss.Color("130")).
				Italic(true),

			HelpText: lipgloss.NewStyle().
				Foreground(lipgloss.Color("8")).
				Italic(true),
		},
	},
}

BuiltinThemes provides predefined themes

Functions

func RegisterReplToTimelineTransformer added in v0.0.29

func RegisterReplToTimelineTransformer(bus *eventbus.Bus)

RegisterReplToTimelineTransformer subscribes to repl.events and publishes timeline lifecycle messages to ui.entities.

Types

type Bridge added in v0.0.29

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

Bridge maps Evaluator events to timeline lifecycle messages via the Shell wrapper to ensure viewport refresh semantics are consistent.

func NewBridge added in v0.0.29

func NewBridge(sh *timeline.Shell) *Bridge

func (*Bridge) Complete added in v0.0.29

func (b *Bridge) Complete(id timeline.EntityID, result map[string]any)

func (*Bridge) Emit added in v0.0.29

func (b *Bridge) Emit(turnID, local, kind string, props map[string]any) timeline.EntityID

func (*Bridge) NewTurnID added in v0.0.29

func (b *Bridge) NewTurnID(seq int) string

func (*Bridge) Patch added in v0.0.29

func (b *Bridge) Patch(id timeline.EntityID, patch map[string]any)

type ClearHistoryMsg

type ClearHistoryMsg struct{}

ClearHistoryMsg is sent when history should be cleared

type Config

type Config struct {
	Title                string
	Prompt               string
	Placeholder          string
	Width                int
	StartMultiline       bool
	EnableExternalEditor bool
	EnableHistory        bool
	MaxHistorySize       int
}

Config holds REPL shell configuration.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns a sensible default configuration.

type EvaluationCompleteMsg

type EvaluationCompleteMsg struct {
	Input  string
	Output string
	Error  error
}

EvaluationCompleteMsg is sent when evaluation is complete

type Evaluator

type Evaluator interface {
	EvaluateStream(ctx context.Context, code string, emit func(Event)) error
	GetPrompt() string
	GetName() string
	SupportsMultiline() bool
	GetFileExtension() string
}

Evaluator executes code and streams events. Errors should be represented as events too (e.g., stderr or result with error annotation), with the returned error used for terminal failures.

type Event added in v0.0.29

type Event struct {
	Kind  EventKind
	Props map[string]any
}

Event carries a semantic payload for the UI.

type EventKind added in v0.0.29

type EventKind string

EventKind enumerates structured output kinds for the timeline.

const (
	EventInput          EventKind = "repl_input"           // recommended to be emitted by REPL shell
	EventResultMarkdown EventKind = "repl_result_markdown" // props: markdown|string in "markdown" or "text"
	EventStdout         EventKind = "repl_stdout"          // props: append|string or text
	EventStderr         EventKind = "repl_stderr"          // props: append|string or text, is_error=true
	EventLog            EventKind = "repl_log"             // props: level, message, metadata(optional), fields(optional)
	EventStructuredLog  EventKind = "repl_structured_log"  // props: level, message(optional), data|metadata|fields
	EventToolCalls      EventKind = "repl_tool_calls"
	EventProgress       EventKind = "repl_progress"
	EventPerf           EventKind = "repl_perf"
	EventTable          EventKind = "repl_table"
	EventDiff           EventKind = "repl_diff"
	EventShellCmd       EventKind = "repl_shell_cmd"
	EventInspector      EventKind = "repl_inspector"
)

type ExampleEvaluator

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

ExampleEvaluator is a simple evaluator for demonstration

func NewExampleEvaluator

func NewExampleEvaluator() *ExampleEvaluator

NewExampleEvaluator creates a new example evaluator

func (*ExampleEvaluator) Evaluate

func (e *ExampleEvaluator) Evaluate(ctx context.Context, code string) (string, error)

Evaluate implements the Evaluator interface

func (*ExampleEvaluator) EvaluateStream added in v0.0.29

func (e *ExampleEvaluator) EvaluateStream(ctx context.Context, code string, emit func(Event)) error

EvaluateStream adapts Evaluate to the streaming interface expected by the REPL timeline.

func (*ExampleEvaluator) GetFileExtension

func (e *ExampleEvaluator) GetFileExtension() string

GetFileExtension returns the file extension for external editor

func (*ExampleEvaluator) GetName

func (e *ExampleEvaluator) GetName() string

GetName returns the evaluator name

func (*ExampleEvaluator) GetPrompt

func (e *ExampleEvaluator) GetPrompt() string

GetPrompt returns the prompt string

func (*ExampleEvaluator) SupportsMultiline

func (e *ExampleEvaluator) SupportsMultiline() bool

SupportsMultiline returns true if multiline is supported

type ExternalEditorCompleteMsg

type ExternalEditorCompleteMsg struct {
	Content string
	Error   error
}

ExternalEditorCompleteMsg is sent when external editor is complete

type ExternalEditorMsg

type ExternalEditorMsg struct {
	Content string
}

ExternalEditorMsg is sent when external editor should be opened

type History

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

History manages command history for the REPL

func NewHistory

func NewHistory(maxSize int) *History

NewHistory creates a new history manager

func (*History) Add

func (h *History) Add(input, output string, isErr bool)

Add adds a new entry to the history

func (*History) Clear

func (h *History) Clear()

Clear clears all history

func (*History) GetAll

func (h *History) GetAll() []string

GetAll returns all input history entries for counting

func (*History) GetEntries

func (h *History) GetEntries() []HistoryEntry

GetEntries returns all history entries

func (*History) IsNavigating

func (h *History) IsNavigating() bool

IsNavigating returns true if currently navigating history

func (*History) NavigateDown

func (h *History) NavigateDown() string

NavigateDown moves down in history (to newer entries)

func (*History) NavigateUp

func (h *History) NavigateUp() string

NavigateUp moves up in history (to older entries)

func (*History) ResetNavigation

func (h *History) ResetNavigation()

ResetNavigation resets the navigation state

type HistoryEntry

type HistoryEntry struct {
	Input  string
	Output string
	IsErr  bool
}

HistoryEntry represents a single entry in the REPL history

type HistoryNavigationMsg

type HistoryNavigationMsg struct {
	Direction string // "up" or "down"
	Entry     string
}

HistoryNavigationMsg is sent when history navigation occurs

type Model

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

Model is a timeline-first REPL shell: timeline transcript + input line.

func NewModel

func NewModel(evaluator Evaluator, config Config, pub message.Publisher) *Model

NewModel constructs a new REPL shell with timeline transcript.

func (*Model) Init

func (m *Model) Init() tea.Cmd

Init subscribes to evaluator events.

func (*Model) Update

func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd)

Update handles TUI events.

func (*Model) View

func (m *Model) View() string

type MultilineModeToggleMsg

type MultilineModeToggleMsg struct {
	Enabled bool
}

MultilineModeToggleMsg is sent when multiline mode is toggled

type QuitMsg

type QuitMsg struct{}

QuitMsg is sent when the REPL should quit

type SlashCommandMsg

type SlashCommandMsg struct {
	Command string
	Args    []string
}

SlashCommandMsg is sent when a slash command is executed

type Styles

type Styles struct {
	Title    lipgloss.Style
	Prompt   lipgloss.Style
	Result   lipgloss.Style
	Error    lipgloss.Style
	Info     lipgloss.Style
	HelpText lipgloss.Style
}

Styles defines the visual styling for the REPL

func DefaultStyles

func DefaultStyles() Styles

DefaultStyles returns the default styling configuration

type Theme

type Theme struct {
	Name   string
	Styles Styles
}

Theme represents a color theme for the REPL

Directories

Path Synopsis
evaluators

Jump to

Keyboard shortcuts

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