services

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 20 Imported by: 0

Documentation

Overview

MCP server: exposes the yoink daemon over the Model Context Protocol (stdio) so agents can manage background processes as native tools instead of shelling out and parsing terminal output.

Every tool is a thin translation into domain.DaemonRequest and back, sent through the same ClientService the CLI uses. The MCP server is a client of the daemon, not a second process manager, so an agent and a human in their own shell see exactly the same set of processes.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DaemonSysProcAttr

func DaemonSysProcAttr() *syscall.SysProcAttr

DaemonSysProcAttr returns SysProcAttr for daemonizing on Unix (new session).

func FormatLogEntries

func FormatLogEntries(entries []domain.LogEntry) string

FormatLogEntries formats log entries with source labels and redaction. ANSI/VT escape sequences are stripped so that log output never corrupts the caller's terminal (e.g. \x1b[?25l from a TUI process hiding the cursor).

func KillProcess

func KillProcess(p *os.Process) error

KillProcess sends SIGKILL to the process.

func ParseProcessRef added in v0.3.0

func ParseProcessRef(ref string) (id int, alias string)

ParseProcessRef splits a user-supplied process reference into the numeric ID and alias fields the daemon protocol expects. A ref that parses as an integer is an ID; anything else is an alias.

func ResolveKey

func ResolveKey(name string) (string, error)

ResolveKey returns the PTY byte sequence for the given key name. Names are case-insensitive (e.g. "Up", "CTRL+C", "PageUp").

func StartProcessWithPTY

func StartProcessWithPTY(cmd *exec.Cmd) (*os.File, error)

StartProcessWithPTY starts the command with a pseudo-terminal attached. The PTY size is set to match the VT emulator size in process_manager.go (220×50).

func TerminateProcess

func TerminateProcess(p *os.Process) error

TerminateProcess sends SIGTERM to the process.

Types

type ClientService

type ClientService struct {
	SockPath string
}

ClientService communicates with the yoink daemon over a Unix socket.

func NewClientService

func NewClientService(sockPath string) *ClientService

NewClientService creates a client that connects to the given socket path.

func (*ClientService) Connect

func (cs *ClientService) Connect() (net.Conn, error)

Connect establishes a connection to the daemon socket.

func (*ClientService) Do

Do sends a request and returns the response, auto-starting the daemon if needed.

func (*ClientService) EnsureDaemon

func (cs *ClientService) EnsureDaemon() error

EnsureDaemon checks if the daemon is running and starts it if not.

func (*ClientService) ReadResponse

func (cs *ClientService) ReadResponse(conn net.Conn) (domain.DaemonResponse, error)

ReadResponse reads and decodes a response from the daemon.

func (*ClientService) SendRequest

func (cs *ClientService) SendRequest(conn net.Conn, req domain.DaemonRequest) error

SendRequest encodes and sends a request to the daemon.

type DaemonServer

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

DaemonServer listens on a Unix socket and manages background processes.

func NewDaemonServer

func NewDaemonServer(sockPath string, pm *ProcessManager, log zerolog.Logger) *DaemonServer

NewDaemonServer creates a new daemon server.

func (*DaemonServer) HandleSingleRequest

func (ds *DaemonServer) HandleSingleRequest(conn io.ReadWriteCloser)

HandleSingleRequest processes one request on the given connection. Exported for testing.

func (*DaemonServer) Start

func (ds *DaemonServer) Start() error

Start begins listening for client connections. Blocks until Stop is called.

func (*DaemonServer) Stop

func (ds *DaemonServer) Stop()

Stop closes the listener and removes the socket file.

type MCPServer added in v0.3.0

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

MCPServer serves yoink's process manager over MCP.

func NewMCPServer added in v0.3.0

func NewMCPServer(client *ClientService, version string) *MCPServer

NewMCPServer builds an MCP server that talks to the daemon behind client.

func (*MCPServer) Serve added in v0.3.0

func (s *MCPServer) Serve(ctx context.Context) error

Serve registers the tools and serves MCP over stdio until ctx is cancelled or the client disconnects.

stdout is the protocol stream: nothing on this path may print to it.

type ProcessManager

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

ProcessManager manages background processes with PTY I/O.

func NewProcessManager

func NewProcessManager(bufSize int) *ProcessManager

NewProcessManager creates a process manager with the given ring buffer size per process.

func (*ProcessManager) AttachOutput

func (pm *ProcessManager) AttachOutput(id int, w io.Writer) error

AttachOutput registers a writer to receive live output for the given process.

func (*ProcessManager) Clean

func (pm *ProcessManager) Clean() int

Clean removes all finished/failed processes and returns the count removed.

func (*ProcessManager) CleanAll added in v0.2.0

func (pm *ProcessManager) CleanAll(force bool) int

CleanAll stops every running process and removes all managed processes, waiting (up to 5s total) for terminated processes to actually exit before removing them. Use force=true to send SIGKILL instead of SIGTERM.

func (*ProcessManager) DetachOutput

func (pm *ProcessManager) DetachOutput(id int)

DetachOutput removes the live output writer for the given process.

func (*ProcessManager) GetLogEntries

func (pm *ProcessManager) GetLogEntries(id, lines int) ([]domain.LogEntry, error)

GetLogEntries returns the last n raw log entries for the given process.

func (*ProcessManager) GetNewOutput

func (pm *ProcessManager) GetNewOutput(id int) (string, error)

GetNewOutput returns only the lines written since the last call and advances the cursor.

func (*ProcessManager) GetOutput

func (pm *ProcessManager) GetOutput(id, lines int) (string, error)

GetOutput returns the last n lines of formatted output for the given process.

func (*ProcessManager) GetPTY

func (pm *ProcessManager) GetPTY(id int) (io.ReadWriteCloser, error)

GetPTY returns the PTY file descriptor for attach operations.

func (*ProcessManager) Kill

func (pm *ProcessManager) Kill(id int, force bool) error

Kill sends a signal to the process. Use force=true for SIGKILL.

func (*ProcessManager) List

func (pm *ProcessManager) List() []domain.ProcessInfo

List returns info for all managed processes.

func (*ProcessManager) ResolveID

func (pm *ProcessManager) ResolveID(ref string) (int, error)

ResolveID resolves an alias or numeric ID string to a process ID.

func (*ProcessManager) SendInput

func (pm *ProcessManager) SendInput(id int, input string, opts SendOptions) error

SendInput writes text to the process PTY. By default it appends a newline; use SendOptions to customise behaviour.

func (*ProcessManager) Shutdown

func (pm *ProcessManager) Shutdown()

Shutdown terminates all running processes and cleans up.

func (*ProcessManager) Snapshot

func (pm *ProcessManager) Snapshot(id int) (string, error)

Snapshot returns the current rendered screen of the process as plain text. It works for both running and finished processes, and correctly handles TUI applications by replaying their escape sequences through a VT100 emulator.

func (*ProcessManager) Spawn

func (pm *ProcessManager) Spawn(command, alias string, opts SpawnOptions) (int, error)

Spawn starts a new background process and returns its ID.

type RingBuffer

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

RingBuffer is a thread-safe circular buffer for storing log entries.

func NewRingBuffer

func NewRingBuffer(size int) *RingBuffer

NewRingBuffer creates a ring buffer with the given capacity.

func (*RingBuffer) Count

func (rb *RingBuffer) Count() int

Count returns the number of entries currently in the buffer.

func (*RingBuffer) ReadAfter

func (rb *RingBuffer) ReadAfter(cursor int) ([]domain.LogEntry, int)

ReadAfter returns entries written after the given cursor and the new cursor. If the cursor is behind the buffer (entries were overwritten), all buffered entries are returned.

func (*RingBuffer) ReadAll

func (rb *RingBuffer) ReadAll() []domain.LogEntry

ReadAll returns all entries in the buffer in chronological order.

func (*RingBuffer) ReadLast

func (rb *RingBuffer) ReadLast(n int) []domain.LogEntry

ReadLast returns the last n entries in chronological order.

func (*RingBuffer) TotalWritten

func (rb *RingBuffer) TotalWritten() int

TotalWritten returns the total number of entries ever written to the buffer.

func (*RingBuffer) Write

func (rb *RingBuffer) Write(entry domain.LogEntry)

Write appends a log entry to the buffer, overwriting the oldest if full.

type SendOptions

type SendOptions struct {
	Redacted  bool
	TypeMode  bool          // send character by character
	TypeDelay time.Duration // delay between characters in type mode
	NoEnter   bool          // omit the trailing newline
	Submit    bool          // append carriage-return Enter instead of newline
}

SendOptions controls how input is delivered to a process PTY.

type SpawnOptions added in v0.2.0

type SpawnOptions struct {
	Cwd     string // working directory for the process; empty uses the daemon's own cwd
	LogFile string // if set, raw PTY output is additionally teed to this file, unbounded by the ring buffer
}

SpawnOptions configures how a new managed process is started.

Jump to

Keyboard shortcuts

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