host

package
v0.2.19 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 14 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package host owns the parts of kitty-browse's native control API that every host shares: the typed action bridge, target pinning and the host-managed operations a visible pane and a headless host must perform identically.

Page actions are executed by internal/action exactly once for both hosts, so a headless browser cannot drift from the visible pane's semantics.

Index

Constants

This section is empty.

Variables

View Source
var (
	// ResultDone is the "done" action result: action mode ended, browser stays.
	ResultDone = json.RawMessage(`{"released":true}`)
	// ResultQuitting is the "quit" action result: the host is shutting down.
	ResultQuitting = json.RawMessage(`{"quitting":true}`)
)

Result documents every host returns unchanged, so a client cannot tell the visible pane from a headless host.

Functions

func BrowserScopedAction

func BrowserScopedAction(name string) bool

BrowserScopedAction reports whether an action addresses the browser rather than one tab.

func CacheTitle

func CacheTitle(titles map[*browser.Session]string, sess *browser.Session)

CacheTitle records one tab's title, bounded so a busy page cannot stall the caller. It is a cache: failures leave the previous title in place.

func CheckViewport

func CheckViewport(width, height int) error

CheckViewport enforces the set.viewport contract for both hosts. The visible pane then renders that size into its cell box; a headless host applies it directly.

func ClientError

func ClientError(code, message string) *action.Error

ClientError builds the API error the contract uses for rejected requests.

func CloseTab

func CloseTab(tabs *browser.Tabs, index int) error

CloseTab closes one tab by displayed index. The last tab is refused with the contract's last_tab error rather than a generic failure.

func DisplayedTabID

func DisplayedTabID(info action.Info, value string) (string, error)

DisplayedTabID resolves the CLI's 1-based displayed tab number to the stable tab ID. Anything that is not a number is already an opaque ID.

func HostManagedAction

func HostManagedAction(name string) bool

HostManagedAction reports whether an action must run on the goroutine that owns the browser's UI state.

func Navigate(ctx context.Context, sess *browser.Session, name, url string, load time.Duration) error

Navigate runs one host-managed navigation action on a session.

func NewBrowserID

func NewBrowserID() string

NewBrowserID returns a fresh opaque browser identity.

func NewTab

func NewTab(ctx context.Context, tabs *browser.Tabs, url string, load time.Duration) error

NewTab opens url in a new tab and leaves it active. An empty URL opens the same blank page the pane's own new-tab control uses.

func PruneTitles

func PruneTitles(titles map[*browser.Session]string, sessions []*browser.Session)

PruneTitles drops cached titles for sessions that are no longer live. The cache is keyed by session pointer, so a session closed by an external client or a closed popup would otherwise stay in the map, and in the tab-strip document, for as long as the browser lives. Tab sets that reconcile against Chromium call this after every reconcile.

func ResolveTabID

func ResolveTabID(info action.Info, req *action.Request) error

ResolveTabID turns the tabId convenience parameter into the stable target ID before the request is queued. The typed target stays authoritative.

func SelectTab

func SelectTab(tabs *browser.Tabs, index int) error

SelectTab activates one tab by displayed index.

func SessionFor

func SessionFor(tabs *browser.Tabs, target action.TabInfo) (*browser.Session, error)

SessionFor returns the session of a previously advertised target. A tab that closed, or whose target moved to another ID, is rejected instead of acted on.

func SetViewport

func SetViewport(sess *browser.Session, width, height int) error

SetViewport validates and applies set.viewport dimensions.

func ViewportDocument

func ViewportDocument(width, height int) (json.RawMessage, error)

ViewportDocument is the set.viewport result.

Types

type Bridge

type Bridge struct {
	ID           string
	LoginProfile string // immutable, assigned by the trusted launcher

	Calls  chan Call
	Active atomic.Int64
	// InputBlocked counts mutating actions only. Read-only observation may run
	// while a person types; it must not cause the pane to discard their keys.
	InputBlocked atomic.Int64
	// contains filtered or unexported fields
}

Bridge publishes immutable discovery snapshots. Native page operations run outside the host loop; tab/navigation/viewport changes are posted back to that loop, which remains the sole owner of models and screencast selection.

func NewBridge

func NewBridge(id string) *Bridge

NewBridge creates a bridge for one browser identity.

func (*Bridge) CloseInteraction added in v0.2.12

func (b *Bridge) CloseInteraction()

Closing a view revokes decisions and receipts in the same critical section used by checked recovery. An already accepted request cannot revive it.

func (*Bridge) ContinuationOutcome added in v0.2.12

func (b *Bridge) ContinuationOutcome(req ContinueRequest) string

func (*Bridge) ContinueChecked added in v0.2.12

func (b *Bridge) ContinueChecked(ctx context.Context, req ContinueRequest) error

ContinueChecked performs a generation compare-and-swap after mutations drain. It neither sends page input nor replays a rejected action.

func (*Bridge) Execute

func (b *Bridge) Execute(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)

Execute serves /v1/actions.

func (*Bridge) ExecuteOperator added in v0.2.11

func (b *Bridge) ExecuteOperator(ctx context.Context, raw json.RawMessage) (json.RawMessage, error)

ExecuteOperator is an authenticated embedding seam, never a control-API action. Only bounded browser chrome operations are accepted by its caller.

func (*Bridge) Information

func (b *Bridge) Information(context.Context) (json.RawMessage, error)

Information serves /v1/info.

func (*Bridge) Interaction added in v0.2.7

func (b *Bridge) Interaction() InteractionState

func (*Bridge) Load

func (b *Bridge) Load() *Snapshot

Load returns the current snapshot, or nil before the first Update.

func (*Bridge) ManualTarget added in v0.2.9

func (b *Bridge) ManualTarget(ctx context.Context, requested action.Target, operation func(*browser.Session) error) error

ManualTarget runs an operator-originated operation on a pinned live tab. It is an in-process primitive, not an action or a control-socket endpoint. An embedding application must authenticate the operator and must never expose this function as a general-purpose automation capability.

A pause blocks automatic mutations, not a person's input. The per-target gate prevents a manual operation from interleaving with an automated action on that target; an already-running mutation on another target also blocks it.

func (*Bridge) NoteInputConflict added in v0.2.7

func (b *Bridge) NoteInputConflict()

func (*Bridge) ObserveIntervention added in v0.2.7

func (b *Bridge) ObserveIntervention(ctx context.Context, sess *browser.Session)

ObserveIntervention latches a pause; disappearance of the challenge alone never authorizes automatic retries. A person explicitly resumes instead.

func (*Bridge) Pause added in v0.2.7

func (b *Bridge) Pause(reason string)

func (*Bridge) RecordExplicitSelection added in v0.2.9

func (b *Bridge) RecordExplicitSelection(tab action.TabInfo)

RecordExplicitSelection is called by the host loop only after an explicit control-API tab activation succeeds. Passive or manual selections must not publish it: other surfaces may be intentionally showing a different tab.

func (*Bridge) Resume added in v0.2.7

func (b *Bridge) Resume()

Resume never replays an interrupted or rejected action.

func (*Bridge) Update

func (b *Bridge) Update(tabs *browser.Tabs, titles map[*browser.Session]string)

Update is called only by the host loop. Published values are never mutated.

type Call

type Call struct {
	Ctx   context.Context
	Req   action.Request
	Reply chan action.Response
}

Call is one host-managed action posted to the goroutine that owns the browser's UI state.

type ContinueRequest added in v0.2.12

type ContinueRequest struct {
	BrowserID       string    `json:"browserId"`
	InstanceEpoch   string    `json:"instanceEpoch"`
	PauseGeneration uint64    `json:"pauseGeneration"`
	RequestID       string    `json:"requestId"`
	ExpiresAt       time.Time `json:"expiresAt"`
}

ContinueRequest is accepted only by the private operator seam. Public automation may observe its generation, but cannot submit a decision.

type InteractionState added in v0.2.7

type InteractionState struct {
	Busy                bool   `json:"busy"`
	Action              string `json:"action,omitempty"`
	ReadOnly            bool   `json:"readOnly,omitempty"`
	Completed           bool   `json:"completed,omitempty"`
	Paused              bool   `json:"paused"`
	Closed              bool   `json:"closed,omitempty"`
	Reason              string `json:"reason,omitempty"`
	InputConflict       bool   `json:"inputConflict,omitempty"`
	BrowserID           string `json:"browserId"`
	InstanceEpoch       string `json:"instanceEpoch"`
	PauseGeneration     uint64 `json:"pauseGeneration"`
	PauseSource         string `json:"pauseSource,omitempty"`
	ResumedGeneration   uint64 `json:"resumedGeneration,omitempty"`
	ContinuationVersion int    `json:"continuationVersion"`
	RetryAfterMS        int64  `json:"retryAfterMs,omitempty"`
}

InteractionState contains labels only, never selectors, typed text or URLs. It is safe to render in the footer or return with browser metadata.

type Quit

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

Quit is the one-shot shutdown request shared by the /v1/quit endpoint, the typed "quit" action and a host's own context. Request is safe to call from any goroutine and any number of times.

func NewQuit

func NewQuit() *Quit

NewQuit creates an unrequested quit signal.

func (*Quit) Done

func (q *Quit) Done() <-chan struct{}

Done is closed after Request.

func (*Quit) Request

func (q *Quit) Request()

Request asks the host to shut down. It never blocks: the caller owns the response that must be delivered before the socket disappears.

func (*Quit) Requested

func (q *Quit) Requested() bool

Requested reports whether a graceful shutdown has been asked for.

type Snapshot

type Snapshot struct {
	Info     action.Info
	Sessions map[string]*browser.Session
}

Snapshot is one immutable discovery view. Published snapshots are never mutated after Update stores them.

Jump to

Keyboard shortcuts

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