ipc

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 17 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 ipc is the local observation and control channel used by `jms attach`.

Transport is a Windows named pipe or a Unix domain socket, owner-only, and it never listens on a network port (DESIGN.md「IPC 宿主」).

The wire protocol is JSON-Lines: the client opens with `hello{role, asset_filter?, last?}`, the host pushes `event`, an `operator` may send `exec{...}` and receives `exec.result`, and `ping`/`pong` keep the channel alive. Arbitration between a human command and an AI command happens at the Exec seam, which shares the terminal pool's per-terminal mutex, so the two callers serialize on one connection instead of racing for it (「IPC 宿主」).

Index

Constants

View Source
const (
	MsgHello      = "hello"
	MsgEvent      = "event"
	MsgExec       = "exec"
	MsgExecResult = "exec.result"
	MsgPing       = "ping"
	MsgPong       = "pong"
)

Message types on the wire (JSON-Lines).

View Source
const (
	// DefaultPingInterval keeps an idle connection alive.
	DefaultPingInterval = 30 * time.Second
)

Defaults.

Variables

This section is empty.

Functions

func EndpointName

func EndpointName(configDir string) string

EndpointName renders the per-user endpoint address.

Windows: \\.\pipe\jms-<hash>; Unix: a 0600 socket under the config dir.

The hash is derived from the config directory so that two installations with separate config directories never collide, and the name stays stable across restarts: the host is addressed, not discovered.

Types

type Client

type Client struct {
	Role        Role
	AssetFilter string
	Last        int
	// OnEvent receives broadcast events.
	OnEvent func(event json.RawMessage)
}

Client is the `jms attach` side.

type Conn

type Conn struct {
	// PingInterval keeps the channel alive.
	PingInterval time.Duration
	// contains filtered or unexported fields
}

Conn is one attached connection.

func Dial

func Dial(ctx context.Context, addr string, c *Client) (*Conn, error)

Dial connects to a host endpoint.

The returned Conn runs a reader goroutine that feeds OnEvent, answers keepalive pings and dispatches exec results.

func (*Conn) Close

func (c *Conn) Close() error

Close closes the connection.

It tolerates a nil receiver and a zero-value Conn: Close is deferred by every caller, so panicking here would mask whatever the command was actually reporting. A zero-value Conn has no transport to close, which is a no-op rather than an error.

func (*Conn) Exec

func (c *Conn) Exec(ctx context.Context, req ExecRequest) (ExecResult, error)

Exec asks the host to run a command.

A host-reported failure comes back as both a non-nil error and the result it arrived in, so a caller can still inspect Busy and ExitCode (「IPC 宿主」).

type Envelope

type Envelope struct {
	Type string          `json:"type"`
	Data json.RawMessage `json:"data,omitempty"`
}

Envelope is one wire message.

type ExecRequest

type ExecRequest struct {
	Server  string `json:"server,omitempty"`
	Asset   string `json:"asset"`
	Command string `json:"command"`
	Account string `json:"account,omitempty"`
}

ExecRequest is an operator's request to run a command.

type ExecResult

type ExecResult struct {
	Output   string `json:"output"`
	ExitCode int    `json:"exit_code"`
	Error    string `json:"error,omitempty"`
	Busy     bool   `json:"busy,omitempty"`
}

ExecResult is the answer to an ExecRequest.

Busy reports that another command (an AI tool call or a second operator) currently holds the terminal: the host refuses rather than queueing unboundedly (「IPC 宿主」).

type Hello

type Hello struct {
	Type        string `json:"type"`
	Role        Role   `json:"role"`
	AssetFilter string `json:"asset_filter,omitempty"`
	Last        int    `json:"last,omitempty"`
}

Hello is the client's opening message.

type Host

type Host struct {
	// Subscribe receives bus events to broadcast. It must not block the
	// caller: a congested client is dropped, never waited for (「可观测性」).
	Subscribe func(sink func(event json.RawMessage))
	// Exec runs an operator command through the shared pool.
	Exec func(ctx context.Context, req ExecRequest) ExecResult
	// Endpoint pins the endpoint address. The empty value means the per-user
	// endpoint derived from the configuration directory.
	//
	// It exists because the CLI's configuration directory is not always
	// config.ConfigDir(): an explicit --config must put the host on the same
	// endpoint that `jms attach` computes, or the two would never meet.
	Endpoint string
	// contains filtered or unexported fields
}

Host is the server side of the channel, embedded in the jms mcp process.

func (*Host) Close

func (h *Host) Close() error

Close tears the endpoint down.

It unblocks Listen, drops every attached client and removes the Unix socket file. It is idempotent.

func (*Host) Listen

func (h *Host) Listen(ctx context.Context) (string, error)

Listen starts the host on the platform's owner-only endpoint and returns its address.

Listen returns once the endpoint is accepting; the endpoint stays up until ctx is cancelled or Close is called.

type Role

type Role string

Role is what a client asks to be.

const (
	RoleObserver Role = "observer"
	RoleOperator Role = "operator"
)

Client roles.

Jump to

Keyboard shortcuts

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