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 ¶
const ( MsgHello = "hello" MsgEvent = "event" MsgExec = "exec" MsgExecResult = "exec.result" MsgPing = "ping" MsgPong = "pong" )
Message types on the wire (JSON-Lines).
const ( // DefaultPingInterval keeps an idle connection alive. DefaultPingInterval = 30 * time.Second )
Defaults.
Variables ¶
This section is empty.
Functions ¶
func EndpointName ¶
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 ¶
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 ¶
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.