Documentation
¶
Overview ¶
Package messenger owns the stream-json process bridge used to deliver a message to an agent session. It is intentionally independent of HTTP and worker entry points so both server-local and worker dispatch paths share the same process lifecycle and environment rules.
Index ¶
- Constants
- type Agent
- type AgentList
- type Delivery
- type Manager
- func (m *Manager) Command() string
- func (m *Manager) ListAgents(ctx context.Context, runner, cwd string, command []string) (AgentList, error)
- func (m *Manager) ResidentMessengerStatus(runner string) string
- func (m *Manager) Send(ctx context.Context, runner, cwd, target string, command []string) (string, error)
- func (m *Manager) SetIdle(idle time.Duration)
- func (m *Manager) Snapshot(runner string) Snapshot
- func (m *Manager) Status(runner string) string
- type Snapshot
Constants ¶
const ( StatusStopped = "stopped" // no resident process StatusIdle = "idle" // process alive, no request in flight StatusBusy = "busy" // a request is queued or in flight )
Status values reported by Manager.Status / Snapshot.Status.
const ( // MaxDeliveries is how many recent deliveries a runner remembers. MaxDeliveries = 20 // MaxStderrTail caps the stderr ring buffer (bytes). MaxStderrTail = 4096 )
const ListAgentsPrompt = "调用 ListAgents 并原样输出结果。不要调用其他工具,不要添加解释。"
ListAgentsPrompt is what the resident process is asked to run. The listing is read from the ListAgents tool_result, so the wording only has to make the model call the tool once.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
Name string `json:"name"`
ShortID string `json:"short_id,omitempty"`
Kind string `json:"kind,omitempty"` // e.g. interactive
Status string `json:"status,omitempty"` // idle | busy | ...
Started string `json:"started,omitempty"`
Cwd string `json:"cwd,omitempty"`
LastActivity string `json:"last_activity,omitempty"`
}
Agent is one session ListAgents reports. Claude's listing carries a name, a short id, a kind, a status and a relative start time; it has NO directory or absolute timestamp, so Cwd/LastActivity stay empty unless a caller fills them from another source (the gofer session registry).
type AgentList ¶
type AgentList struct {
Self string `json:"self,omitempty"` // the messenger's own session name
Agents []Agent `json:"agents"`
RawOutput string `json:"raw_output"`
}
AgentList is the parsed ListAgents result. RawOutput is always the text the parser worked from, so nothing is lost when the format changes.
func ParseAgents ¶
ParseAgents turns the ListAgents listing into rows. It is deliberately tolerant: code fences are stripped, unknown "·" segments are ignored, and lines that do not look like a session row are skipped. RawOutput keeps the original text.
type Delivery ¶
type Delivery struct {
At int64 `json:"at"` // unix seconds the request started
Op string `json:"op,omitempty"` // "send" | "list_agents"
Target string `json:"target,omitempty"` // target session name (send)
Message string `json:"message,omitempty"` // excerpt, <= 200 runes
OK bool `json:"ok"`
Error string `json:"error,omitempty"`
DurationMS int64 `json:"duration_ms,omitempty"`
}
Delivery is the summary of one request sent through the resident process. Message holds a short excerpt (never the full text) so the history is useful without becoming a second message log.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager keeps one stream-json Claude process per local runner. A process is never shared with a remote worker; remote paths use the worker's own Manager.
func New ¶
New creates a resident messenger manager. Non-positive idle values use the shipped ten minute default, matching the pre-package implementation.
func (*Manager) Command ¶
Command is the configured messenger binary ("" on a worker, where each dispatch carries its own command).
func (*Manager) ListAgents ¶
func (m *Manager) ListAgents(ctx context.Context, runner, cwd string, command []string) (AgentList, error)
ListAgents asks the resident process for the sessions Claude Code can message. command only supplies the binary (command[0]); the prompt is fixed.
func (*Manager) ResidentMessengerStatus ¶
ResidentMessengerStatus preserves the session-relay assembly seam while the implementation lives in this package.
func (*Manager) Send ¶
func (m *Manager) Send(ctx context.Context, runner, cwd, target string, command []string) (string, error)
Send writes one stream-json request and waits for its result. target is the addressed session's name; it only labels the delivery history.
func (*Manager) SetIdle ¶
SetIdle updates the idle lifetime used by newly created resident processes. Existing processes keep their current timer until the next request refreshes it.
type Snapshot ¶
type Snapshot struct {
Status string `json:"status"`
StartedAt int64 `json:"started_at,omitempty"`
LastUsedAt int64 `json:"last_used_at,omitempty"`
IdleDeadline int64 `json:"idle_deadline,omitempty"`
Deliveries []Delivery `json:"deliveries,omitempty"`
StderrTail string `json:"stderr_tail,omitempty"`
}
Snapshot is a point-in-time, JSON-friendly view of one runner's messenger. Times are unix seconds (0 = never). Deliveries are newest first.