uirequest

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2026 License: MIT Imports: 23 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

Index

Constants

View Source
const (
	CreateKindShell    = "shell"
	CreateKindWorktree = "worktree"
)
View Source
const (
	ResolvedCurrentShell = "current-shell"
	ResolvedShell        = "shell"
	ResolvedProject      = "project"
	ResolvedInstance     = "instance"
)

How a request chose its destination. Values are stable for --json callers.

View Source
const DefaultTTL = 15000 * time.Millisecond

DefaultTTL is the default time-to-live for a request.

Variables

This section is empty.

Functions

func AcksDirPath

func AcksDirPath(stateDir, id string, action Action) string

AcksDirPath returns the directory holding acknowledgements for a request.

func Announce

func Announce(stateDir string, inst Instance) error

Announce writes (or replaces) this process's presence file.

func Cleanup

func Cleanup(stateDir, reqID string, action Action) error

Cleanup removes a request file and its associated acks directory.

func DiffTarget

func DiffTarget(workDir, value string) workspacediff.Target

DiffTarget turns a request Value into a workspacediff.Target. Hosts re-resolve in workDir (no shell) so a crafted request cannot skip rev-parse. An unresolvable spec is still returned parsed — the leaf load reports the error.

func Dir

func Dir(stateDir string) (string, error)

Dir returns and ensures the requests directory under stateDir.

func HostName

func HostName() string

HostName is the machine name reported in acks, with a stable fallback.

func InstanceID

func InstanceID(surface string) string

InstanceID identifies one acknowledging host surface. A single Sidecar process hosts more than one surface that can answer a request (the project Workspaces plugin and the global Workspaces browser), and each ack is a file named after this id — so the surface has to be part of it or one host's ack silently overwrites the other's.

func InstancePath

func InstancePath(stateDir string, pid int) string

InstancePath is the presence file for pid.

func InstancesDir

func InstancesDir(stateDir string) (string, error)

InstancesDir returns and ensures the instance-presence directory.

func NewRequestID

func NewRequestID() string

NewRequestID generates a sortable unique identifier for a request.

func RequestPath

func RequestPath(stateDir, id string, action Action) string

RequestPath returns the absolute path for a request file.

func Sweep

func Sweep(stateDir string, now time.Time) error

Sweep removes expired requests and leftover temporary files.

func Withdraw

func Withdraw(stateDir string, pid int) error

Withdraw removes this process's presence file. Liveness is still the authority; a crash that skips this is cleaned up by ListInstances.

func WriteAck

func WriteAck(stateDir, reqID string, action Action, ack Ack) error

WriteAck writes an acknowledgement file for an instance.

func WriteRequest

func WriteRequest(stateDir string, req Request) (string, error)

WriteRequest atomically creates the request file and its matching acks directory.

Types

type Ack

type Ack struct {
	Instance string    `json:"instance"`
	Host     string    `json:"host"`
	PID      int       `json:"pid"`
	Status   Status    `json:"status"`
	Reason   string    `json:"reason,omitempty"`
	Surface  string    `json:"surface,omitempty"`
	Pane     int       `json:"pane,omitempty"`
	At       time.Time `json:"at"`
}

Ack is the acknowledgement written by each Sidecar instance handling a request.

func ReadAcks

func ReadAcks(stateDir, reqID string, action Action) ([]Ack, error)

ReadAcks collects all acks for a given request.

type Action

type Action string

Action identifies the requested UI presentation mutation.

const (
	ActionOpen           Action = "open"
	ActionRenameWorktree Action = "rename-worktree"
	ActionRenameShell    Action = "rename-shell"
	// ActionCreate selects a shell or worktree the CLI just recorded. The
	// durable write has already happened; the payload is the selection cue.
	ActionCreate Action = "create"
	// ActionNotify posts (or dismisses) a notification in a running instance.
	// Its payload is a notification record rather than a target, because the
	// object it names does not exist until the request lands.
	ActionNotify Action = "notify"
)

type CreatePayload added in v1.3.0

type CreatePayload struct {
	Kind        string `json:"kind"`
	Session     string `json:"session,omitempty"`
	DisplayName string `json:"displayName,omitempty"`
	Focus       *bool  `json:"focus,omitempty"`
	Path        string `json:"path,omitempty"`
	Branch      string `json:"branch,omitempty"`
	Run         string `json:"run,omitempty"`
	Type        string `json:"type,omitempty"`
}

CreatePayload is the ActionCreate record. Kind distinguishes a workspace shell from a worktree; Focus defaults to true when omitted. Run/Type are the split-mode seeds executed in the terminal-panel session after it exists.

func DecodeCreatePayload added in v1.3.0

func DecodeCreatePayload(raw json.RawMessage) (CreatePayload, error)

func (CreatePayload) ShouldFocus added in v1.3.0

func (p CreatePayload) ShouldFocus() bool

type Instance

type Instance struct {
	PID        int       `json:"pid"`
	Host       string    `json:"host"`
	ProjectKey string    `json:"projectKey"`
	Project    string    `json:"project"`
	WorkDir    string    `json:"workDir"`
	StartedAt  time.Time `json:"startedAt"`
}

Instance is a live Sidecar TUI process, announced under the state dir so `sidecar open` can address it from outside a project shell.

func ListInstances

func ListInstances(stateDir string) ([]Instance, error)

ListInstances returns live same-host presence records and sweeps dead files.

type Options

type Options struct {
	Split string `json:"split,omitempty"` // "auto", "right", "below"
}

Options specifies optional placement flags. There is deliberately no focus option: an open request never moves the user's selection or focus.

type Origin

type Origin struct {
	TmuxSession string `json:"tmuxSession"`
	Namespace   string `json:"namespace"`
	ProjectKey  string `json:"projectKey"`
	WorkDir     string `json:"workDir"`
	PID         int    `json:"pid"`
}

Origin identifies the calling process and its owning Sidecar project shell.

type Request

type Request struct {
	Version   int       `json:"version"`
	ID        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	TTLMs     int       `json:"ttlMs"`
	Origin    Origin    `json:"origin"`
	Action    Action    `json:"action"`
	Target    Target    `json:"target"`
	Options   Options   `json:"options,omitempty"`
	// Payload carries an action-specific record for actions whose object is
	// not addressable as a Target — a posted notification, so far. It is raw
	// JSON so uirequest stays a transport and does not import the packages
	// that own these records.
	Payload json.RawMessage `json:"payload,omitempty"`
}

Request is the payload written by the CLI into the request bus.

func ReadRequest

func ReadRequest(path string) (Request, error)

ReadRequest reads and parses a request from path.

type RequestMsg

type RequestMsg struct {
	Request Request
}

RequestMsg is emitted to BubbleTea when a UI request is detected in the state tree.

type ResolveOptions

type ResolveOptions struct {
	// Diff is sidecar open --diff. A missing positional becomes the working
	// tree (wt). A positional is a git spec, including HEAD and branch names.
	Diff bool
	// Provider is sidecar open --provider <instance>. It short-circuits every
	// other classification: with it, the positional is a provider locator and
	// nothing else, so a ticket key that happens to name a file cannot be
	// silently reinterpreted.
	Provider string
}

ResolveOptions controls how ResolveTarget classifies a CLI argument.

type Result

type Result struct {
	Action    Action `json:"action"`
	Target    Target `json:"target"`
	Shell     string `json:"shell"`
	Name      string `json:"name"`
	Project   string `json:"project"`
	Resolved  string `json:"resolved"`
	Delivered int    `json:"delivered"`
	Results   []Ack  `json:"results"`
}

Result is the consolidated outcome presented to the agent or caller.

type Status

type Status string

Status describes the host's response to a UI request.

const (
	StatusOpened     Status = "opened"
	StatusQueued     Status = "queued"
	StatusRetargeted Status = "retargeted"
	StatusDeclined   Status = "declined"
	StatusError      Status = "error"
)

type Target

type Target struct {
	Kind  TargetKind `json:"kind"`
	Value string     `json:"value"`
	Line  int        `json:"line"`
	// Provider is the configured provider instance for TargetKindResource and
	// is empty for every other kind. It is required rather than guessed: a
	// bare locator must not make the CLI start provider discovery or choose
	// among instances.
	Provider string `json:"provider,omitempty"`
	// Matcher is the provider-stable matcher ID for TargetKindResource when the
	// sender already knows it — a scanned resource span does, because a live
	// matcher claimed the locator to produce the span. It is empty for every
	// other kind and for senders (the CLI) with no matcher snapshot, and a host
	// with one fills it in.
	Matcher string `json:"matcher,omitempty"`
}

Target identifies the object affected by the request. Value carries the action-specific path, issue ID, or presentation value.

func ResolveResourceTarget added in v1.0.3

func ResolveResourceTarget(provider, raw string) (Target, error)

ResolveResourceTarget validates a --provider request without contacting anything. Matching the locator to a matcher is the running app's job: it holds the live snapshot, and a short-lived CLI process must never start a provider to answer `sidecar open`.

func ResolveTarget

func ResolveTarget(workDir, raw string, explicitLine int, opts ResolveOptions) (Target, error)

ResolveTarget parses and validates a target string against the shell's workspace root.

Classification, in order:

  1. td- issue id (even with --diff)
  2. --diff with no positional → working tree (Value "wt")
  3. --diff with a positional → ParseSpec + ResolveSpec
  4. Existing regular file inside workDir (a real file named abc1234 wins)
  5. ParseSpec + ResolveSpec → TargetKindDiff
  6. Usage error (a missing file is not fatal until hash resolution also fails)

func TargetFromSpan added in v1.2.0

func TargetFromSpan(span terminallink.Span) (Target, bool)

TargetFromSpan maps a scanned terminal-link span onto the cross-surface target vocabulary. It is the one span→Target translation: the surfaces used to each keep their own, and the two drifted. It resolves nothing — a span arrives already resolved by the scanner's Resolve hooks — so it is safe anywhere, including a render pass.

Raw wins over Value for file and diff spans because Raw is the token as the text wrote it; the surfaces re-resolve it against their own root on activation, exactly as they did before.

A resource span carries both halves of its identity — Provider and Matcher — because a live matcher already claimed the locator to produce the span; the host does not have to guess which matcher owns it a second time.

It reports false only for spans this vocabulary does not carry, so a caller keeps its existing branch rather than mistaking "not mapped" for "malformed".

type TargetKind

type TargetKind string

TargetKind identifies the type of object affected by a UI request.

const (
	TargetKindFile TargetKind = "file"
	// TargetKindURL is an http(s) link. Activation validates it with
	// terminallink.SafeHTTPURL and refuses anything else; it is never a
	// scheme the app hands to the OS unchecked.
	TargetKindURL      TargetKind = "url"
	TargetKindIssue    TargetKind = "issue"
	TargetKindDiff     TargetKind = "diff"
	TargetKindWorktree TargetKind = "worktree"
	TargetKindShell    TargetKind = "shell"
	// TargetKindResource is an external terminal resource provider's locator.
	// Provider names the configured instance; the running app decides which of
	// that instance's matchers claims the locator, because only it has a live
	// matcher snapshot. The short-lived CLI process starts no provider.
	TargetKindResource TargetKind = "resource"
	// TargetKindNotification is a notification id. Its Value is empty on a
	// post (the id travels in the payload) and set on a dismiss.
	TargetKindNotification TargetKind = "notification"
	// TargetKindSession is a tmux session name to attach. Sidecar-owned names
	// are detected in text (terminallink.KindSession); any name may be
	// attached by a poster that names one.
	TargetKindSession TargetKind = "session"
	// TargetKindTask is a task in the embedded Tasks UI. Nothing detects one
	// in text — a task id is bare 8-hex, indistinguishable from a short sha —
	// so it only ever arrives from a poster that named it.
	TargetKindTask TargetKind = "task"
	// TargetKindNote is a td note identity (nt-…). sidecar open sidecar://note/<id>
	// is the agent-facing form; the pane is a read-only card, not the Notes editor.
	TargetKindNote TargetKind = "note"
)

type Watcher

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

Watcher monitors the $XDG_STATE_HOME/sidecar/requests directory for incoming requests.

func NewWatcher

func NewWatcher(stateDir string) (*Watcher, error)

NewWatcher creates a watcher for UI requests under stateDir.

func (*Watcher) Messages

func (w *Watcher) Messages() <-chan tea.Msg

Messages returns the channel Start emits on. The channel belongs to the watcher, not to whoever called Start: a Bubble Tea model re-arming its listener each time a request arrives reads it from here, so the re-arm cannot depend on a field assignment surviving a value-receiver Init.

func (*Watcher) Start

func (w *Watcher) Start() <-chan tea.Msg

Start begins watching and returns the channel emitting RequestMsg.

func (*Watcher) Stop

func (w *Watcher) Stop()

Stop terminates the watcher and cleans up resources.

Jump to

Keyboard shortcuts

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