Documentation
¶
Overview ¶
Package tuiosctl is golder's narrow Go client for the tuios daemon's line-delimited JSON protocol. It is deliberately not a general tuios CLI: only the verbs the pane tools need are exposed, each with a typed request and response.
Index ¶
- Constants
- func Available() bool
- func Decode[T any](raw json.RawMessage) (T, error)
- type Capture
- type Client
- func (c *Client) Call(ctx context.Context, verb string, params any) (json.RawMessage, error)
- func (c *Client) CallInto(ctx context.Context, verb string, params any, out any) error
- func (c *Client) CapturePane(ctx context.Context, window, source string, lines int, styled bool) (Capture, error)
- func (c *Client) Close() error
- func (c *Client) CloseWindow(ctx context.Context, window string) error
- func (c *Client) FocusWindow(ctx context.Context, window string) (string, error)
- func (c *Client) GetWindow(ctx context.Context, window string) (Window, error)
- func (c *Client) ListWindows(ctx context.Context) (WindowList, error)
- func (c *Client) MoveWindow(ctx context.Context, window string, workspace int, follow bool) (MoveResult, error)
- func (c *Client) NewWindow(ctx context.Context, p NewWindowParams) (NewWindowResult, error)
- func (c *Client) NewWindowInCallerWorkspace(ctx context.Context, p NewWindowParams) (NewWindowResult, error)
- func (c *Client) PaneID() string
- func (c *Client) PasteText(ctx context.Context, window, text string, submit bool) (string, error)
- func (c *Client) RenameWindow(ctx context.Context, window, name string) (RenameResult, error)
- func (c *Client) ResizeWindow(ctx context.Context, window string, width, height int) (ResizeResult, error)
- func (c *Client) Restrict(ctx context.Context, readOnly bool) error
- func (c *Client) Run(ctx context.Context, window, command string, timeout time.Duration, lines int) (RunResult, error)
- func (c *Client) Screenshot(ctx context.Context, p ScreenshotParams) (ScreenshotResult, error)
- func (c *Client) SendKeys(ctx context.Context, window, keys string, repeat int) error
- func (c *Client) SendText(ctx context.Context, window, text string, submit bool) (string, error)
- func (c *Client) Session() string
- func (c *Client) SetMinimized(ctx context.Context, window string, minimized bool) (RenameResult, error)
- func (c *Client) WaitFor(ctx context.Context, p WaitParams) (WaitResult, error)
- type Error
- type MoveResult
- type NewWindowParams
- type NewWindowResult
- type Options
- type RenameResult
- type ResizeResult
- type RunResult
- type ScreenshotParams
- type ScreenshotResult
- type WaitParams
- type WaitResult
- type Window
- type WindowList
Constants ¶
const ( // EnvEnv marks a process started inside a tuios pane. EnvEnv = "TUIOS_ENV" // EnvSocket is the daemon socket a pane belongs to. EnvSocket = "TUIOS_SOCKET" // EnvSession is the pane's session name. EnvSession = "TUIOS_SESSION" // EnvPaneID is the pane's window id. EnvPaneID = "TUIOS_PANE_ID" // EnvPaneToken proves the pane id where the kernel cannot. EnvPaneToken = "TUIOS_PANE_TOKEN" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Capture ¶
type Capture struct {
Type string `json:"type"`
Source string `json:"source"`
Content string `json:"content"`
HistoryRows int `json:"history_rows"`
Revision uint64 `json:"revision"`
BootID string `json:"boot_id"`
}
Capture is a pane snapshot. It is never used as a polling loop; callers use WaitFor for that.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is one reusable JSON connection. Calls are serialized because the protocol processes one request per connection at a time. A call that fails at the transport level — a timeout, a broken write, a reply that cannot be read or that answers another request's id — closes the connection, so the next call starts from a clean hello rather than reading a late reply as its own answer. A daemon restart therefore costs the call in flight, never the client; a verb the daemon declined leaves the connection in step and usable.
func Dial ¶
Dial connects, sends hello, and returns a ready client. hello is advisory in the tuios protocol, so an older daemon's unknown_verb is not fatal; every other handshake failure is.
func (*Client) Call ¶
Call invokes one verb and returns its raw result. The context deadline bounds the round trip; without one, defaultCallTTL applies.
func (*Client) CapturePane ¶
func (c *Client) CapturePane(ctx context.Context, window, source string, lines int, styled bool) (Capture, error)
CapturePane takes one snapshot of a pane's visible content or recent scrollback.
func (*Client) CloseWindow ¶
CloseWindow closes an exact window. The tool layer guards the caller's own pane; this method itself only forwards the id.
func (*Client) FocusWindow ¶
FocusWindow moves focus to an exact window.
func (*Client) GetWindow ¶
GetWindow returns one pane by exact id or name. It is not used to validate a destructive target: an attached TUI may omit window_id from its response, so callers use the authoritative ListWindows enumeration for that.
func (*Client) ListWindows ¶
func (c *Client) ListWindows(ctx context.Context) (WindowList, error)
ListWindows returns every pane in the caller's session.
func (*Client) MoveWindow ¶ added in v1.4.10
func (c *Client) MoveWindow(ctx context.Context, window string, workspace int, follow bool) (MoveResult, error)
MoveWindow moves an existing pane to another workspace.
func (*Client) NewWindow ¶
func (c *Client) NewWindow(ctx context.Context, p NewWindowParams) (NewWindowResult, error)
NewWindow creates a pane. command is an argv, never a shell string, so a caller cannot smuggle shell syntax through this tool.
func (*Client) NewWindowInCallerWorkspace ¶ added in v1.5.1
func (c *Client) NewWindowInCallerWorkspace(ctx context.Context, p NewWindowParams) (NewWindowResult, error)
NewWindowInCallerWorkspace creates a helper pane beside the agent's pane, independent of whichever workspace the person is currently looking at. Never fall back to current_workspace or focused_window_id: doing so recreates the focus race this method exists to avoid. An explicitly moved agent pane is followed on the next creation because we resolve its location afresh.
func (*Client) PaneID ¶ added in v1.5.0
PaneID is the pane this process runs in, or "" outside one. The tool layer uses it to mark the pane it must never close.
func (*Client) PasteText ¶ added in v1.4.10
PasteText sends text as a paste, so a multi-line payload is not executed line by line by the receiving shell. submit presses Enter after the paste.
func (*Client) RenameWindow ¶ added in v1.4.10
RenameWindow changes a pane's display name.
func (*Client) ResizeWindow ¶ added in v1.4.10
func (c *Client) ResizeWindow(ctx context.Context, window string, width, height int) (ResizeResult, error)
ResizeWindow changes one pane's PTY size.
func (*Client) Restrict ¶
Restrict gives up authority on this connection. Read tools use own/read_only so the daemon enforces the same limit the tool layer intends.
func (*Client) Run ¶
func (c *Client) Run(ctx context.Context, window, command string, timeout time.Duration, lines int) (RunResult, error)
Run types one command at a shell prompt, waits for its OSC 133 finish mark, and returns its output. It is the no-poll path for "run and give me the result".
func (*Client) Screenshot ¶ added in v1.5.0
func (c *Client) Screenshot(ctx context.Context, p ScreenshotParams) (ScreenshotResult, error)
Screenshot renders one pane to a file on the daemon's machine and returns its path. An older daemon without the verb fails with invalid_verb, which the caller surfaces as "tuios is too old for screenshots".
func (*Client) SendKeys ¶ added in v1.5.0
SendKeys sends named keys to a pane, such as Enter, Tab or ctrl+c.
func (*Client) SendText ¶
SendText writes literal text to a pane. submit adds the Enter path the daemon uses for a harness prompt; a plain shell command should include a trailing newline instead.
A daemon older than 0.8.3 has no submit parameter. The text is sent without it and Enter is pressed with send-keys; the returned note says so.
func (*Client) Session ¶
Session is the session this client is bound to. Tools never accept a caller-supplied session.
func (*Client) SetMinimized ¶ added in v1.4.10
func (c *Client) SetMinimized(ctx context.Context, window string, minimized bool) (RenameResult, error)
SetMinimized minimizes or restores a pane without closing its process.
func (*Client) WaitFor ¶
func (c *Client) WaitFor(ctx context.Context, p WaitParams) (WaitResult, error)
WaitFor blocks on the daemon's event hub and returns as soon as the condition matches. A daemon timeout is returned as a *Error with code "timeout"; the tool turns that into a structured result for the model.
type Error ¶
type Error struct {
Code string `json:"code"`
Message string `json:"message"`
Hint json.RawMessage `json:"hint,omitempty"`
}
Error is a daemon-side verb error. It is separate from transport errors so a caller can act on the stable code (for example timeout vs window_not_found) without parsing prose.
type MoveResult ¶ added in v1.4.10
type MoveResult struct {
Type string `json:"type"`
WindowID string `json:"window_id"`
FromWorkspace int `json:"from_workspace"`
Workspace int `json:"workspace"`
CurrentWorkspace int `json:"current_workspace"`
}
MoveResult reports where a pane went.
type NewWindowParams ¶
type NewWindowResult ¶
type Options ¶
type Options struct {
Socket string
Session string
PaneID string
// Proof is the pane's TUIOS_PANE_TOKEN. The field is named for what it
// does, and is never logged.
Proof string
// Version is sent in hello. Tests use it to identify a fake client.
Version string
}
Options locates one daemon and the pane the process runs in.
type RenameResult ¶ added in v1.4.10
type RenameResult struct {
Type string `json:"type"`
WindowID string `json:"window_id"`
DisplayName string `json:"display_name"`
Minimized bool `json:"minimized"`
}
RenameResult is the pane's name after set-window.
type ResizeResult ¶ added in v1.4.10
type ResizeResult struct {
Type string `json:"type"`
Width int `json:"width"`
Height int `json:"height"`
}
ResizeResult is the PTY size after a resize.
type RunResult ¶
type RunResult struct {
Type string `json:"type"`
Session string `json:"session"`
Window string `json:"window"`
Cmdline string `json:"cmdline"`
ExitCode *int `json:"exit_code,omitempty"`
DurationMS int64 `json:"duration_ms"`
CommandSeq uint64 `json:"command_seq"`
Output string `json:"output"`
Truncated bool `json:"truncated"`
}
RunResult is one shell command's answer. Output is plain text from the pane's OSC 133 command region.
type ScreenshotParams ¶ added in v1.5.0
type ScreenshotParams struct {
Window string
Format string // png, svg, ansi, html, txt
Frame string // window, plain, none
Theme string
Out string
Scrollback bool
Lines int
Cursor bool
}
ScreenshotParams asks the daemon to render a pane to a file.
type ScreenshotResult ¶ added in v1.5.0
type ScreenshotResult struct {
Path string `json:"path"`
Host string `json:"host"`
Format string `json:"format"`
Cols int `json:"cols"`
Rows int `json:"rows"`
Bytes int `json:"bytes"`
Warnings []string `json:"warnings"`
}
ScreenshotResult is where the daemon wrote a pane picture.
type WaitParams ¶
type WaitParams struct {
Condition string
Window string
Pattern string
Idle time.Duration
Until []string
CommandSeq uint64
Timeout time.Duration
}
WaitParams selects one wait-for condition. It is deliberately a struct, not a verb+params map: the tool schema and the daemon params stay one shape.
type WaitResult ¶
type WaitResult struct {
Type string `json:"type"`
Condition string `json:"condition"`
Matched bool `json:"matched"`
Window string `json:"window"`
Pattern string `json:"pattern"`
State string `json:"state"`
Cmdline string `json:"cmdline"`
ExitCode *int `json:"exit_code,omitempty"`
DurationMS int64 `json:"duration_ms"`
CommandSeq uint64 `json:"command_seq"`
}
WaitResult is the successful answer to wait-for.
type Window ¶
type Window struct {
WindowID string `json:"window_id"`
Title string `json:"title"`
DisplayName string `json:"display_name"`
Workspace int `json:"workspace"`
Focused bool `json:"focused"`
Width int `json:"width"`
Height int `json:"height"`
ForegroundCmd string `json:"foreground_cmd"`
AgentState string `json:"agent_state"`
HistoryRows int `json:"history_rows"`
Revision uint64 `json:"revision"`
// Own marks the pane running this golder process, when it is known. It is
// computed by the tool, not sent by the daemon.
Own bool `json:"own,omitempty"`
// Controlled marks a helper pane this agent launched through its broker. It
// is computed by the tool, not accepted from daemon metadata or pane titles.
Controlled bool `json:"controlled,omitempty"`
}
Window is the compact pane description the tools expose. The daemon sends more fields; only what a caller can act on is kept.