entry

package
v1.17.0 Latest Latest
Warning

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

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

Documentation

Overview

Package entry is the shared TUI attach entry point consumed by both `harbor tui --attach` (cmd_tui.go) and the public `sdk/tui.Run` facade.

It encapsulates the connection-only attach flow: resolve the token, build the Protocol client, probe RuntimeInfo, construct the Controller, build the RuntimeModel, and run the Bubble Tea program. The entry point holds NO Runtime, stack, event-bus, or server handle — it is a pure Protocol client consumer, preserving the client-only boundary.

`sdk/tui` forwards to Run through this package; `cmd/harbor/cmd_tui.go` calls Run directly. Both paths share one implementation so the attach experience is identical regardless of how the TUI is launched.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, opts Options) error

Run executes the complete attach flow: resolve token, build client, probe RuntimeInfo, construct Controller, build RuntimeModel, run the Bubble Tea program. Returns nil on clean quit, an error on any failure (auth, network, state, terminal).

The flow is identical to cmd_tui.go's runTUI — extracted here so `sdk/tui.Run` and `harbor tui --attach` share one implementation.

Types

type Options

type Options struct {
	// BaseURL is the Runtime REST/SSE base URL (e.g. http://127.0.0.1:8686).
	BaseURL string
	// Token is the rotating JWT source. Resolved before every request and
	// SSE reconnect. When nil, TokenResolver MUST be non-nil.
	Token protocolclient.TokenSource
	// Session is the authorized session to restore or select. May be empty;
	// the entry point restores the last durable session when blank.
	Session string
	// TokenResolver, when non-nil, resolves the initial token + source path
	// from a file or environment. When Token is already set, this is nil.
	TokenResolver TokenResolver
	// StateFile is the local interaction-state path. Empty defaults to
	// ~/.harbor/tui-state.json.
	StateFile string
	// Compact selects compact transcript presentation.
	Compact bool
	// CompactSet reports whether the caller explicitly set Compact (via
	// --compact / --compact=false). When true, the explicit value — even
	// false — overrides any stored-true preference restored from local
	// interaction state. When false, the stored preference wins (the
	// default for SDK callers that never pass a flag).
	CompactSet bool
	// Input / Output are explicit stream overrides for tests and embedders.
	// When BOTH are nil — the normal CLI, co-launch, and attach case — the
	// entry point mounts on the process terminal: Bubble Tea performs its
	// own input discovery (falling back to /dev/tty when stdin is not a
	// terminal, so a redirected stdin is ignored and a caller with no
	// controlling terminal fails loudly), and alternate-scroll wheel
	// reporting is enabled for the program's lifetime. Setting either
	// stream bypasses that discovery and drives the program over the
	// supplied streams exactly (a nil counterpart falls back to the
	// process stdio); window size is then whatever the supplied output
	// reports — real for a terminal file, absent for a test buffer.
	Input  io.Reader
	Output io.Writer
	// Now is the clock for token expiry checks. Defaults to time.Now.
	Now func() time.Time
}

Options carries the connection-only inputs Run consumes. No Runtime, stack, or server handle is present — the boundary is Protocol-only.

type TokenResolver

type TokenResolver func(ctx context.Context, session string) (token string, sourcePath string, err error)

TokenResolver resolves a bearer credential and its source path for one attach. The cmd_tui.go path injects its resolveTUIAuth/resolveTUIInitialToken pair; sdk/tui injects a simpler static-file resolver. A nil resolver means the caller has already supplied a TokenSource and no file resolution is needed.

Jump to

Keyboard shortcuts

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