tuiosctl

package
v1.5.141 Latest Latest
Warning

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

Go to latest
Published: Nov 25, 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 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

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

func (c *Client) PaneID() string

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

func (c *Client) PasteText(ctx context.Context, window, text string, submit bool) (string, 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) 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

func (c *Client) SendKeys(ctx context.Context, window, keys string, repeat int) error

SendKeys sends named keys to a pane, such as Enter, Tab or ctrl+c.

func (*Client) SendText

func (c *Client) SendText(ctx context.Context, window, text string, submit bool) (string, 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.

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

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) Socket added in v1.5.44

func (c *Client) Socket() string

Socket is the daemon endpoint this client is bound to. It is used only for in-process identity binding (for example a session-scoped pane lease); tools never accept a caller-supplied replacement.

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
	// Broker-created helpers receive none, so raw daemon calls made by a
	// shell/browser cannot escape the agent's tool authorization path.
	Grants      []string
	Focus       bool
	CloseOnExit bool
	KeepOpen    bool
}

type NewWindowResult

type NewWindowResult struct {
	Type      string `json:"type"`
	WindowID  string `json:"window_id"`
	Name      string `json:"name"`
	Workspace int    `json:"workspace,omitempty"`
	Focused   bool   `json:"focused,omitempty"`
	KeepOpen  bool   `json:"keep_open,omitempty"`
}

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 PaneControlAgent added in v1.5.44

type PaneControlAgent struct {
	AgentID      string `json:"agent_id"`
	Label        string `json:"label"`
	Project      string `json:"project"`
	Role         string `json:"role"`
	Conversation string `json:"conversation_id"`
	PaneID       string `json:"pane_id"`
	Workspace    int    `json:"workspace"`
}

PaneControlAgent is one online top-level Golder agent eligible to receive an exclusive pane write lease in the current workspace. It is Golder-computed metadata, not daemon authority.

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"`
	Cwd           string `json:"cwd,omitempty"`
	CwdHost       string `json:"cwd_host,omitempty"`
	// 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
	// also marks an external pane the operator explicitly leased to this agent
	// session. It is computed by the tool, never accepted from daemon metadata or
	// pane titles; the fields below say whether input is actually reusable.
	Controlled bool `json:"controlled,omitempty"`
	// ControlOrigin is "agent-created" or "operator-claimed". ControlScope is
	// "session" for reusable authority and "one-call" for a sealed helper.
	ControlOrigin  string `json:"control_origin,omitempty"`
	ControlScope   string `json:"control_scope,omitempty"`
	ControlOwner   string `json:"control_owner,omitempty"`
	ControlOwnerID string `json:"control_owner_id,omitempty"`
	// InputAllowed is nil for an uncontrolled pane. A non-nil false is emitted so
	// list never hides the difference between controlled and currently usable.
	InputAllowed  *bool  `json:"input_allowed,omitempty"`
	Sealed        bool   `json:"sealed,omitempty"`
	ControlReason string `json:"control_reason,omitempty"`
}

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"`
	ControlAgents    []PaneControlAgent `json:"control_agents,omitempty"`
}

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