tuiosctl

package
v1.4.11 Latest Latest
Warning

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

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 12 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 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

View Source
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

func Available

func Available() bool

Available reports whether this process is running inside a tuios pane that exposes a daemon socket and session name.

func Decode

func Decode[T any](raw json.RawMessage) (T, error)

Decode is for tests that need a typed result from a raw fixture.

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 times out closes the connection so the next call starts from a clean hello.

func Dial

func Dial(ctx context.Context, opts Options) (*Client, error)

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

func (c *Client) Call(ctx context.Context, verb string, params any) (json.RawMessage, error)

Call invokes one verb and returns its raw result. The context deadline bounds the round trip; without one, defaultCallTTL applies.

func (*Client) CallInto

func (c *Client) CallInto(ctx context.Context, verb string, params any, out any) error

CallInto invokes one verb and decodes its result into out.

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) Close

func (c *Client) Close() error

Close closes the connection. It is safe to call more than once.

func (*Client) CloseWindow

func (c *Client) CloseWindow(ctx context.Context, window string) error

CloseWindow closes an exact window. The tool layer guards the caller's own pane; this method itself only forwards the id.

func (*Client) FocusWindow

func (c *Client) FocusWindow(ctx context.Context, window string) (string, error)

FocusWindow moves focus to an exact window.

func (*Client) GetWindow

func (c *Client) GetWindow(ctx context.Context, window string) (Window, error)

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) PasteText added in v1.4.10

func (c *Client) PasteText(ctx context.Context, window, text string, submit bool) error

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

func (c *Client) RenameWindow(ctx context.Context, window, name string) (RenameResult, error)

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

func (c *Client) Restrict(ctx context.Context, readOnly bool) error

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) SendText

func (c *Client) SendText(ctx context.Context, window, text string, submit bool) error

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.

func (*Client) Session

func (c *Client) Session() string

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.

func (*Error) Error

func (e *Error) Error() string

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 NewWindowParams struct {
	Name        string
	Cwd         string
	Workspace   int
	Command     []string
	Focus       bool
	CloseOnExit bool
}

type NewWindowResult

type NewWindowResult struct {
	Type     string `json:"type"`
	WindowID string `json:"window_id"`
	Name     string `json:"name"`
}

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.

func FromEnv

func FromEnv() Options

FromEnv reads the tuios variables every pane receives.

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 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"`
}

Window is the compact pane description the tools expose. The daemon sends more fields; only what a caller can act on is kept.

type WindowList

type WindowList struct {
	Type             string   `json:"type"`
	Total            int      `json:"total"`
	FocusedWindowID  string   `json:"focused_window_id"`
	CurrentWorkspace int      `json:"current_workspace"`
	Windows          []Window `json:"windows"`
}

WindowList is one session's panes across every workspace.

Jump to

Keyboard shortcuts

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