Documentation
¶
Index ¶
- Constants
- Variables
- func AcksDirPath(stateDir, id string, action Action) string
- func Announce(stateDir string, inst Instance) error
- func Cleanup(stateDir, reqID string, action Action) error
- func DiffTarget(workDir, value string) workspacediff.Target
- func Dir(stateDir string) (string, error)
- func HostName() string
- func InstanceID(surface string) string
- func InstancePath(stateDir string, pid int) string
- func InstancesDir(stateDir string) (string, error)
- func NewRequestID() string
- func OriginForeground(origin Origin, attention []Attention) bool
- func PublishAttention(stateDir string, attention Attention) error
- func RequestPath(stateDir, id string, action Action) string
- func Sweep(stateDir string, now time.Time) error
- func ValidateLayoutMove(move LayoutMove) error
- func ValidateLayoutSpec(spec LayoutSpec) error
- func Withdraw(stateDir string, pid int) error
- func WithdrawAttention(stateDir string, pid int) error
- func WriteAck(stateDir, reqID string, action Action, ack Ack) error
- func WriteRequest(stateDir string, req Request) (string, error)
- type Ack
- type AckItem
- type Action
- type Attention
- type CreatePayload
- type Instance
- type LayoutMove
- type LayoutMoveForm
- type LayoutMoveTarget
- type LayoutPane
- type LayoutPayload
- type LayoutSpec
- type LayoutSpecColumn
- type Options
- type Origin
- type Request
- type RequestMsg
- type ResolveOptions
- type Result
- type Status
- type Target
- func ResolveDiffSpec(workDir, raw string) (Target, error)
- func ResolveFileTarget(workDir, raw string, explicitLine int) (Target, error)
- func ResolveResourceTarget(provider, raw string) (Target, error)
- func ResolveTarget(workDir, raw string, explicitLine int, opts ResolveOptions) (Target, error)
- func TargetFromSpan(span terminallink.Span) (Target, bool)
- type TargetKind
- type Watcher
Constants ¶
const ( LayoutModeGet = "get" LayoutModeApply = "apply" LayoutModeMove = "move" )
Layout modes. Get answers with the current layout; apply opens panes; move repositions one pane that is already open.
const ( CreateKindShell = "shell" CreateKindWorktree = "worktree" )
const ( ItemVerdictOpened = "opened" ItemVerdictRetargeted = "retargeted" ItemVerdictDeclined = "declined" // ItemVerdictCarried is a --spec pane that was KEPT, not opened: the // {"kind":"primary"} entry every spec must carry, and a shell carried by // session. Nothing was created for it and nothing was destroyed — the spec // accounted for a live leaf, which is the whole reason those entries are // mandatory. Reporting it as "opened" told an agent a pane appeared when // the same pane had been there all along. ItemVerdictCarried = "carried" // ItemVerdictMoved is layout move's accepted outcome: this pane changed // position and Cell names where it landed. ItemVerdictMoved = "moved" // ItemVerdictUnchanged is an accepted no-op. Cell names where the pane still // is, and Reason says why nothing moved. ItemVerdictUnchanged = "unchanged" )
Per-pane verdicts for an ActionLayout apply. They ride beside Status, which stays the overall outcome: on a decline, Items still lists EVERY requested pane with the verdict each earned during validation, and Reason names the first violation.
const ( ResolvedCurrentShell = "current-shell" ResolvedShell = "shell" ResolvedProject = "project" ResolvedInstance = "instance" ResolvedSessions = "sessions" )
How a request chose its destination. Values are stable for --json callers.
const DefaultTTL = 15000 * time.Millisecond
DefaultTTL is the default time-to-live for a request.
Variables ¶
var LayoutMoveDirections = []string{"left", "right", "up", "down"}
LayoutMoveDirections is the accepted direction vocabulary, in help order.
Functions ¶
func AcksDirPath ¶
AcksDirPath returns the directory holding acknowledgements for a request.
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 HostName ¶
func HostName() string
HostName is the machine name reported in acks, with a stable fallback.
func InstanceID ¶
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 ¶
InstancePath is the presence file for pid.
func InstancesDir ¶
InstancesDir returns and ensures the instance-presence directory.
func NewRequestID ¶
func NewRequestID() string
NewRequestID generates a sortable unique identifier for a request.
func OriginForeground ¶ added in v1.11.0
OriginForeground reports whether any focused live instance is visibly showing the notification origin. An unresolved origin is background.
func PublishAttention ¶ added in v1.11.0
PublishAttention atomically replaces this process's attention record.
func RequestPath ¶
RequestPath returns the absolute path for a request file.
func ValidateLayoutMove ¶ added in v1.11.0
func ValidateLayoutMove(move LayoutMove) error
ValidateLayoutMove checks a move record's grammar. It knows nothing about the current tree: which pane sits at a cell, whether the destination fits, and every cap and floor are the host's to answer.
func ValidateLayoutSpec ¶ added in v1.7.0
func ValidateLayoutSpec(spec LayoutSpec) error
ValidateLayoutSpec checks a spec's grammar: shape within the caps, known kinds, exactly one primary, and the fields each kind takes. It knows nothing about the CURRENT tree — live-leaf accounting, target resolution, and floors are the host's to answer. Both surfaces share it so a CLI usage error and a host decline can never disagree about what a valid spec is.
func Withdraw ¶
Withdraw removes this process's presence file. Liveness is still the authority; a crash that skips this is cleaned up by ListInstances.
func WithdrawAttention ¶ added in v1.11.0
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"`
// ItemsVersion names the shape of Items whenever Items is present; 1 today.
// Callers gate on it instead of guessing, so the array can grow without
// breaking an agent that parsed yesterday's acks.
ItemsVersion int `json:"itemsVersion,omitempty"`
Items []AckItem `json:"items,omitempty"`
// Layout carries the ActionLayout get-mode answer verbatim: the layout
// report the host built from its focused surface's tree. Empty for every
// other action and for apply acks.
Layout json.RawMessage `json:"layout,omitempty"`
}
Ack is the acknowledgement written by each Sidecar instance handling a request.
type AckItem ¶ added in v1.7.0
type AckItem struct {
Index int `json:"index"`
Verdict string `json:"verdict"`
Cell string `json:"cell,omitempty"`
Surface string `json:"surface,omitempty"`
Pane int `json:"pane,omitempty"`
Reason string `json:"reason,omitempty"`
}
AckItem is one requested pane's verdict: what became of it, where it landed (cell "col.row" and surface), and — when declined — why.
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" // ActionConfigReload tells live instances that a targeted CLI save has // completed. The config file remains authoritative; the request carries no // settings payload for a host to trust or merge. ActionConfigReload Action = "config-reload" // ActionLayout reads or composes a surface's pane layout in one request. // Like notify, its object is not addressable as a Target: the payload is a // LayoutPayload naming the mode and, for apply, every requested pane. The // ack carries per-pane verdicts (Items) and, for get, the layout report // itself (Layout). ActionLayout Action = "layout" )
type Attention ¶ added in v1.11.0
type Attention struct {
PID int `json:"pid"`
Host string `json:"host"`
Focused bool `json:"focused"`
VisibleOrigin Origin `json:"visibleOrigin,omitempty"`
UpdatedAt time.Time `json:"updatedAt"`
}
Attention is one live Sidecar instance's host-visible focus context.
func ListAttention ¶ added in v1.11.0
ListAttention returns live same-host records and discards malformed, stale, or dead-process files using the same PID liveness rule as ListInstances.
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 ¶
ListInstances returns live same-host presence records and sweeps dead files.
type LayoutMove ¶ added in v1.11.0
type LayoutMove struct {
From string `json:"from,omitempty"`
Focused bool `json:"focused,omitempty"`
To string `json:"to"`
}
LayoutMove is the ActionLayout move record: which pane moves and where. Exactly one source form is set — Focused for the surface's focused pane, or From as a pre-move grid cell "col.row" — and To names the destination.
To is carried VERBATIM rather than pre-resolved because the direction words mean what the keyboard and the modal mean by them, and only the host has the tree to ask. The CLI validates the grammar with ParseLayoutMoveTo and the host resolves it against panelayout, so neither can drift.
type LayoutMoveForm ¶ added in v1.11.0
type LayoutMoveForm int
LayoutMoveForm names how a To value addresses its destination.
const ( // LayoutMoveCell is "col.row" in the pre-move grid. LayoutMoveCell LayoutMoveForm = iota // LayoutMoveColumn is a bare column number: append at the bottom of that // column, opening one past the last if it does not exist yet. LayoutMoveColumn // LayoutMoveDirection is left/right/up/down, resolved by the same // panelayout.MoveDirection rule the modal's h/j/k/l use. LayoutMoveDirection )
type LayoutMoveTarget ¶ added in v1.11.0
type LayoutMoveTarget struct {
Form LayoutMoveForm
Cell panelayout.Cell
Column int
Direction panelayout.Direction
}
LayoutMoveTarget is a validated To value. Exactly one field is meaningful, named by Form.
func ParseLayoutMoveTo ¶ added in v1.11.0
func ParseLayoutMoveTo(value string) (LayoutMoveTarget, error)
ParseLayoutMoveTo validates one --to value. A bare number is a column, so it is checked before the cell form, which would otherwise read "3" as 3.1.
type LayoutPane ¶ added in v1.7.0
type LayoutPane struct {
Kind string `json:"kind"`
Targets []string `json:"targets,omitempty"`
At string `json:"at,omitempty"`
// Provider names the configured terminal resource provider instance for
// kind resource. Required there and ignored elsewhere: a bare locator is
// never guessed at.
Provider string `json:"provider,omitempty"`
Run string `json:"run,omitempty"`
Type string `json:"type,omitempty"`
Name string `json:"name,omitempty"`
// Session carries a shell pane's tmux session. Set means CARRY that live
// leaf; empty with run/type/name means open a new split beside the origin.
Session string `json:"session,omitempty"`
}
LayoutPane is one requested pane of an apply batch or one cell of a full --spec layout. Kind uses the layout vocabulary's wire names: primary, file, issue, diff, resource, shell, note. The first target opens the pane and the rest join it as tabs of the same kind; shells carry run/type/name instead of targets. At is an optional grid cell "col.row" (1-based) — a requirement, refused rather than re-placed — meaningful only in the batch form: in a spec a pane's position IS its column and row.
A live leaf is CARRIED into a spec with exactly what `layout get` prints: {"kind":"primary"} for the host's own terminal, {"kind":"shell","session": "<tmux-session>"} for a split terminal. A spec that omits a live leaf is declined naming the session (apply never destroys a live terminal).
type LayoutPayload ¶ added in v1.7.0
type LayoutPayload struct {
Mode string `json:"mode"`
Panes []LayoutPane `json:"panes,omitempty"`
Columns json.RawMessage `json:"columns,omitempty"`
Move *LayoutMove `json:"move,omitempty"`
}
LayoutPayload is the ActionLayout record. Apply carries either the batch's Panes or a full-layout Columns spec, never both; get carries neither; move carries only its Move record.
func DecodeLayoutPayload ¶ added in v1.7.0
func DecodeLayoutPayload(raw json.RawMessage) (LayoutPayload, error)
type LayoutSpec ¶ added in v1.7.0
type LayoutSpec struct {
Columns []LayoutSpecColumn `json:"columns"`
}
LayoutSpec is the full-layout grammar: 1..MaxGridColumns columns, each stacking 1..MaxGridRows panes. It is the JSON shape decision 5 settled and what a `layout get` grid projects back onto, so get → edit → apply is a round trip without translation.
func DecodeLayoutSpec ¶ added in v1.7.0
func DecodeLayoutSpec(raw json.RawMessage) (LayoutSpec, error)
type LayoutSpecColumn ¶ added in v1.7.0
type LayoutSpecColumn struct {
Panes []LayoutPane `json:"panes"`
}
LayoutSpecColumn is one column of a LayoutSpec: its panes, top to bottom.
func DecodeLayoutColumns ¶ added in v1.7.0
func DecodeLayoutColumns(raw json.RawMessage) ([]LayoutSpecColumn, error)
DecodeLayoutColumns decodes the ActionLayout payload's columns field: the spec's column array itself, since the payload already names the mode.
type Options ¶
type Options struct {
Split string `json:"split,omitempty"` // "auto", "right", "below"
// At is an explicit grid cell "col.row" (1-based) for a single open. It is
// a requirement, not a preference: a kind whose open would retarget an
// existing pane, and any cell that cannot be honored exactly, decline
// rather than land elsewhere — the deliberate divergence from Split, which
// only ever overrides an axis. At and Split are mutually exclusive.
At string `json:"at,omitempty"`
}
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"`
// Sessions is true when the request addresses the running instance's
// global Sessions surface rather than a project workspace. The project
// plugin ignores these; the overview answers them.
Sessions bool `json:"sessions,omitempty"`
// SessionsRow is the durable inventory ID of the Sessions row. Empty
// means the currently selected row.
SessionsRow string `json:"sessionsRow,omitempty"`
// HostID names the registered remote host a workspace lives on. Empty
// means this machine. It is set on an attention record's visible origin so
// "the user is looking at that workspace" cannot be answered by a local
// workspace that merely shares a tmux session name with a remote one.
HostID string `json:"hostId,omitempty"`
}
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 ¶
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" // StatusMoved is an accepted layout move: a pane that was already open // changed position. Nothing opened and nothing closed, which is why it is // its own word rather than StatusOpened. StatusMoved Status = "moved" // StatusUnchanged is an accepted request that had nothing to do — a move to // the cell the pane already occupies, or a direction with no room beyond it. // It is a success, not a refusal, and deliberately not StatusRetargeted: // nothing was re-pointed at anything. StatusUnchanged Status = "unchanged" )
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 ResolveDiffSpec ¶ added in v1.7.0
ResolveDiffSpec is resolveDiffTarget's exported form: diff-only classification for callers that have already chosen the kind. An empty raw resolves to the working tree, matching `sidecar open --diff`.
func ResolveFileTarget ¶ added in v1.7.0
ResolveFileTarget is resolveFileTarget's exported form: file-only classification for callers that have already chosen the kind (the pane switcher's File picker). It is the same resolution `sidecar open` runs, so both produce one target shape.
func ResolveResourceTarget ¶ added in v1.0.3
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:
- td- issue id (even with --diff)
- --diff with no positional → working tree (Value "wt")
- --diff with a positional → ParseSpec + ResolveSpec
- Existing regular file inside workDir (a real file named abc1234 wins)
- ParseSpec + ResolveSpec → TargetKindDiff
- 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 ¶
NewWatcher creates a watcher for UI requests under stateDir.
func (*Watcher) Messages ¶
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.