Documentation
¶
Overview ¶
Package relay lets one lich session hand a prompt to another and get an answer back, for the providers whose own CLI has no cross-session channel of its own. Claude Code has one; Codex, opencode, oh-my-pi and Crush do not, and this works the same for all five.
The delivery is deliberately dumb: lich hands the message to the target's mod where one runs (Claude Code with lich-plugin), and otherwise types it at the target's prompt and submits it, exactly as the user would. What it never does is read the answer off the terminal — a TUI's output is boxes, spinners and ANSI, and parsing it would mean a parser per provider, each hostage to a release. Instead the message it delivers asks the agent to report back by running `lich reply <ticket>`, so the answer is *written by the agent that produced it*. That is what keeps this provider-agnostic: anything that can run a shell command can answer.
Index ¶
- Constants
- Variables
- func IsRosterName(name, cwd string) bool
- func IsUnansweredReason(reason string) bool
- func QuotedList(names []string) string
- func RosterName(cwd, id string) string
- func RosterNameOf(recorded, cwd, id string) string
- func SpawnBriefing(lang prompt.Lang, hasTools bool, route SubagentRoute) string
- type CollectNowOptions
- type CollectOptions
- type Collected
- type Events
- type FocusEvent
- type FocusOptions
- type Focused
- type HandedPrompt
- type InboxEvent
- type InsertOptions
- type Inserted
- type Notification
- type OpenErrand
- type OwedErrand
- type Peer
- type PeersOptions
- type Plugins
- type PromptReceipt
- type ReadyErrand
- type RelayEvent
- type ReplyOptions
- type Result
- type ScheduleEvent
- type SelfOptions
- type SendOptions
- type Service
- func (s *Service) AnnounceMerge(checkout string, number int, title, branch, base string) error
- func (s *Service) Collect(ctx context.Context, opts CollectOptions) (Collected, error)
- func (s *Service) CollectNow(opts CollectNowOptions) (Collected, error)
- func (s *Service) Focus(opts FocusOptions) (Focused, error)
- func (s *Service) Insert(opts InsertOptions) (Inserted, error)
- func (s *Service) Observe(sessionID, state string)
- func (s *Service) ParkResume(id string, resetsAt int64)
- func (s *Service) Peers(opts PeersOptions) ([]Peer, error)
- func (s *Service) Reply(opts ReplyOptions) error
- func (s *Service) RunSchedules()
- func (s *Service) Self(opts SelfOptions) (Peer, error)
- func (s *Service) Send(ctx context.Context, opts SendOptions) (Result, error)
- func (s *Service) SendPrivate(ctx context.Context, opts SendOptions) (Result, error)
- func (s *Service) SendSubagent(ctx context.Context, opts SendOptions) (Result, error)
- func (s *Service) SessionClosed(sessionID, closerID string)
- func (s *Service) SessionExited(sessionID string)
- func (s *Service) SetPlugins(plugins Plugins)
- func (s *Service) SetPromptLanguage(lang func() prompt.Lang)
- func (s *Service) SetRaiseWindow(raise func(sessionID string))
- func (s *Service) SetWorkerFinished(fn func(workerID string) error)
- func (s *Service) Status(id string) Status
- func (s *Service) Wait(ctx context.Context, opts WaitOptions) (Result, error)
- func (s *Service) WorkerAnswered(workerID, text string)
- func (s *Service) WorkerUnanswered(workerID, reason string)
- type Sessions
- type StalledEvent
- type Status
- type SubagentRoute
- type Terminal
- type WaitOptions
Constants ¶
const ( // DefaultWait is how long Send blocks before handing the caller a ticket to // come back with. It sits under the 120s an agent's shell tool typically // allows a command, so a long errand ends in an answer this side chose — // "still working, wait on this ticket" — instead of a killed process and no // way back to the conversation. DefaultWait = 100 * time.Second // MaxWait bounds an explicit timeout. Past this the caller should be // polling with Wait, not holding a socket. MaxWait = 30 * time.Minute )
const ( // MCPServerName namespaces the tools in a client's list // (`mcp__lich__send_to_session` in Claude Code) and is the key lich // registers itself under. MCPServerName = "lich" // MCPSubcommand is the `lich` subcommand that serves them. MCPSubcommand = "mcp" // ToolReply answers a relayed message. It is the one tool named in prose, // because the receiving agent is told what to call. ToolReply = "reply_to_session" // ToolCollect drains the results waiting for a sender. Named in prose too: // the nudge typed at a sender's prompt is what tells it the tool exists. ToolCollect = "wait_for_answer" )
How lich's own MCP server (internal/cli) is registered and what it calls its tools. They live here rather than beside the server because two other places need them and neither may depend on that one: the message this package composes has to name the reply tool, and the spawn path (internal/terminal) has to name the command to register. The server itself already depends on this package, so this is the only direction that closes no cycle.
const ( // StatusAnswered means the target's agent replied and Answer holds it. StatusAnswered = "answered" // StatusPending means the message was delivered and the wait ran out first. // The ticket is still live: Wait picks the same answer up later. StatusPending = "pending" // StatusUnread means the task was typed at the target's prompt and nothing // there read it: the session never started working. See watchReceipt. StatusUnread = "unread" // StatusUnanswered means the target worked through the request and ended its // turn without replying here. Its answer, if it wrote one, is in that // session's own terminal and nowhere lich can read it — which is what // happens when an agent answers over a channel of its provider's own. StatusUnanswered = "unanswered" // StatusUndelivered means the task never reached a prompt: it was held back // for a session that was not at one, and that session died or stayed busy // past defaultDeliveryLimit. Nothing is queued anymore and nothing was read. StatusUndelivered = "undelivered" // StatusStopped means a subagent worker was closed before it answered // (SessionClosed). A caller that closed it itself hears it only while // holding the line, or when it is itself a worker somebody waits on; a // worker anyone else closed has it filed in its caller's inbox. StatusStopped = "stopped" // StatusExpired means nobody answered within ticketTTL and the ticket was // dropped (sweep). Only a sender that is itself a worker somebody waits on // hears it, filed in its inbox; any other sender finds the ticket unknown. StatusExpired = "expired" )
Status values a Result carries.
const ( DirectionOut = "out" DirectionIn = "in" )
Directions a RelayEvent carries. An empty direction clears the mark: the request it named is over, answered or expired.
const ( PromptWithdrawn = "withdrawn" // no poll collected it, and it never runs PromptDelivered = "delivered" // a poll carried it, and no ack came back yet PromptAcked = "acked" // the mod acked it: OK and Reason say how it went PromptEnded = "ended" // the session exited first )
How far a prompt handed to a mod got (docs/hooks/mod-control.md).
const ( NotifyCompleted = "completed" // a subagent worker reported, or a pull request merged NotifyWaiting = "waiting" // a subagent worker is blocked on a permission )
The statuses a Notification carries.
const ( UnansweredBlank = "blank" UnansweredError = "error" UnansweredRefusal = "refusal" )
The reasons a worker's mod gives for a turn that ended with nothing left running and no answer (docs/hooks/mod-answer.md, Unanswered turns).
const FocusEventName = "session-focus"
FocusEventName asks the window to open a session's card, the way a click on it does. Global like the other session events: the card it names may live in a project whose tab is not the one on screen.
const InboxEventName = "session-inbox"
InboxEventName carries how many uncollected results a session has waiting, so its card can say so — the nudge tells the agent, and this tells the person. Emitted whenever a sender's inbox changes size; zero clears the mark. Global for the same reason the relay event is.
const MaxWaitSeconds = int(MaxWait / time.Second)
MaxWaitSeconds is MaxWait in the unit every caller states a wait in. Exported because the clamp has to happen before the multiplication that would overflow it, which means every surface taking a number of seconds needs the bound itself rather than the Duration (internal/cli, waitBudget).
const RelayEventName = "session-relay"
RelayEventName carries which session is waiting on which, so the sidebar can say it. Global rather than per-session because its consumer — one store keyed by id — outlives any one card, exactly as the status event's does.
const ScheduleEventName = "session-schedule"
ScheduleEventName is emitted when a session's scheduled prompt changes without the window having written it: delivered, or parked and dropped by lich itself around a usage limit (resume.go). Payload: ScheduleEvent.
const StalledEventName = "session-relay-stalled"
StalledEventName carries a request whose target ended its turn without answering through lich. The window turns it into a toast that opens the target's card, because the answer — if there is one — is on that screen and the person who asked has no other way to know where it went.
Variables ¶
var ErrNoMod = errors.New("no lich-plugin mod polls from this session")
ErrNoMod is what Terminal.SubmitPrompt answers for a session no mod polls from, which is every session but a Claude Code one running lich-plugin's mod.
Functions ¶
func IsRosterName ¶
IsRosterName reports whether name has the shape RosterName gives a session born in cwd, whatever its id: how a Claude Code conversation lich opened is told from one somebody started by hand, after lich has lost the row (terminal.Conversations). A name the user typed into `/rename` matches only by coincidence.
func IsUnansweredReason ¶
IsUnansweredReason is whether reason is one the contract names.
func QuotedList ¶
QuotedList words a list of names (session labels, folders) for a message: each one quoted, so a name with a comma or a trailing space still reads as one.
func RosterName ¶
RosterName builds the name lich gives a session at birth: the last element of its working directory, then four characters of its id. cwd is the session's own directory when it has one (a worktree) and its project's otherwise.
Exported for the one caller outside this package that mints a session rather than resolving one: internal/spawn, which reports the name it opened a session under.
func RosterNameOf ¶
RosterNameOf is the name a session answers to in the peer roster now. recorded is what its agent has on record (terminal.AgentName) and wins outright: a `/rename` typed inside a session changes the name the harness answers to, and no derivation can see that. Falling back to the derived one covers everything with nothing recorded — a provider that is never handed a roster name, a conversation lich cannot read, a session whose first turn has not been written yet.
func SpawnBriefing ¶
func SpawnBriefing(lang prompt.Lang, hasTools bool, route SubagentRoute) string
SpawnBriefing is what a provider is told about lich when lich starts it: two sentences appended to its system prompt, for the providers whose command line accepts one (internal/terminal, briefingFlags).
It exists because the agent's own harness offers subagents of its own, and those are described to it at length, in its system prompt, from its first turn. lich's tools are described in a server block far below that — so an agent asked to "fan this out across worktrees" reaches for the subagent it was told about, and the user watches work they meant to supervise disappear into a process they cannot open, on a checkout that does not exist. Reported twice by the same user before this text existed.
It draws the line rather than forbidding anything: a subagent is still the right tool for a throwaway read. What it fixes is the one case the agent cannot get right on its own, because nothing in its prompt says lich sessions are visible and steerable and subagents are not.
lang is the session's prompt language; every locale keeps to the quoting rule below (see prompt.Catalog).
hasTools is whether this provider was handed lich's MCP server at spawn. The command line works everywhere and is named for the ones that were not, on the same rule replyInstruction follows: naming a tool a session does not have is worse than naming the command.
The example spells its placeholders in capitals and quotes with ' rather than the usual <angle brackets> and ": this string is passed as one argv entry, and a provider shipped as a .cmd is spawned through `cmd.exe /c` (internal/terminal, wrapArgv). Windows escapes a double quote as \" for CommandLineToArgvW, cmd.exe does not read that as an escape, and the < and > left outside quotes by it are redirection.
route is where this spawn's own subagents run (SubagentRoute), which decides what the agent is sent to for fanning work out.
Types ¶
type CollectNowOptions ¶
type CollectNowOptions struct {
From string `json:"from"`
}
CollectNowOptions is one CollectNow call, an object for the reason SendOptions is one.
type CollectOptions ¶
CollectOptions is one Collect call, an object for the reason SendOptions is one.
type Collected ¶
Collected is what a drain returns: every outcome that was waiting for the caller, oldest first, and the labels of the sessions still owing one.
type Events ¶
Events is where the relay announces a request in flight. The app's event hub implements it; a nil one leaves the feature working and silent, which is the state a test that only exercises delivery is in.
type FocusEvent ¶
type FocusEvent struct {
ID string `json:"id"`
}
FocusEvent is the payload of FocusEventName.
type FocusOptions ¶
type FocusOptions struct {
From string `json:"from"`
Target string `json:"target"`
Project string `json:"project"`
}
FocusOptions is one Focus call, an object for the reason SendOptions is one.
type Focused ¶
type Focused struct {
ID string `json:"id"`
Label string `json:"label"`
Project string `json:"project"`
}
Focused says which session's card was brought up, so a caller that named it loosely can tell the person which one it was.
type HandedPrompt ¶
type HandedPrompt struct {
// Await waits for the mod's ack until ctx ends, and says how far the
// prompt got.
Await func(context.Context) PromptReceipt
// Collected reports whether a poll has carried the prompt to the mod yet.
Collected func() bool
}
HandedPrompt is a prompt queued for a session's mod.
type InboxEvent ¶
InboxEvent is the payload of InboxEventName.
type InsertOptions ¶
type InsertOptions struct {
From string `json:"from"`
Target string `json:"target"`
Project string `json:"project"`
Text string `json:"text"`
WaitSeconds int `json:"waitSeconds"`
}
InsertOptions is one Insert call, an object for the reason SendOptions is one.
type Inserted ¶
type Inserted struct {
ID string `json:"id"`
Label string `json:"label"`
Project string `json:"project"`
Kind string `json:"kind"`
// Bytes is what was pasted, after control characters were stripped (sanitize).
Bytes int `json:"bytes"`
}
Inserted says where the text went, so an editor can tell the person which session took it when the target was chosen for them.
type Notification ¶
Notification asks the mod to submit a prompt as news from outside the session: Claude Code shows Summary as one line where the prompt would be, and the model reads the text whole (docs/hooks/mod-control.md, A prompt as a notification).
type OpenErrand ¶
type OpenErrand struct {
Ticket string `json:"ticket"`
Target string `json:"target"`
State string `json:"state"`
}
OpenErrand is a request the session handed out that has not ended. State is stateQueued until the task is delivered, then what the target last reported.
type OwedErrand ¶
type OwedErrand struct {
Ticket string `json:"ticket"`
From string `json:"from"`
Asked string `json:"asked"`
}
OwedErrand is a request handed to the session that it has not answered. From is the asking session's label, empty for the command line.
type Peer ¶
type Peer struct {
Label string `json:"label"`
Name string `json:"name"`
Project string `json:"project"`
Kind string `json:"kind"`
State string `json:"state"`
// ID is the session's lich id, the LICH_SESSION_ID its process carries,
// so a reader holding a recorded id can find its card. Last, because
// fields are appended to this shape, never inserted.
ID string `json:"id"`
// Path is the directory the session runs in, the worktree's for a worktree
// session, and ProjectPath the root of the project it belongs to. They are
// what an editor matches its open folder against to find the session beside
// it; the name of a project says nothing about where it is.
Path string `json:"path"`
ProjectPath string `json:"projectPath"`
}
Peer is one session a caller may address: the label it is addressed by, the name it answers to in Claude Code's peer roster, the project it belongs to (labels are unique within a project, not across them), what is running in it, and what that session last reported it was doing.
Both names are published because both reach this session and an agent sees them in different places — the label on the card, the roster name in `/list-agents` and in what a mention writes at a prompt. Showing one and accepting the other is what made an agent treat a single session as two.
State is stateBusy, stateWaiting or stateDone, and empty when the session has reported nothing — which is a provider whose plugin does not report state as much as a session that has not had a turn yet. Empty is "not known", never "idle": guessing the second is how a caller ends up sending work into a session that cannot take it.
type PeersOptions ¶
type PeersOptions struct {
From string `json:"from"`
}
PeersOptions is one Peers call, an object for the reason SendOptions is one.
type Plugins ¶
type Plugins interface {
// Installed is whether those sessions report their state to lich at all,
// which is what makes a missing report mean something (see watchReceipt).
Installed(kind string) bool
// HasTools is whether they can call lich's own operations, which decides
// whether a relayed message names a tool or the shell command.
HasTools(kind string) bool
}
Plugins is what the relay needs to know about the companion plugin (internal/agentplugin implements it). Both questions are about a provider's sessions rather than about one session, because that is the grain the plugin is installed at.
type PromptReceipt ¶
PromptReceipt is what became of one prompt handed to a mod. An ack OK means its turn started.
type ReadyErrand ¶
type ReadyErrand struct {
Ticket string `json:"ticket"`
Target string `json:"target"`
Status string `json:"status"`
}
ReadyErrand is an outcome waiting in the session's inbox.
type RelayEvent ¶
type RelayEvent struct {
ID string `json:"id"`
Peer string `json:"peer"`
Direction string `json:"direction"`
Ticket string `json:"ticket"`
}
RelayEvent is the payload of RelayEventName: the session whose mark changed, the label at the other end, which way the request runs, and the ticket the two ends share. Peer is empty when the other end is not a session at all — the CLI run from a script or a shell — which the card words its own way.
The ticket rides along because it is otherwise written down in exactly one place: the message typed at the target's prompt. An agent whose context was compacted past that message has no way back to it, and neither had the person watching — the window knew a request was open and could not say which one. Empty when the mark is being cleared, along with the direction.
type ReplyOptions ¶
type ReplyOptions struct {
From string `json:"from"`
Ticket string `json:"ticket"`
Answer string `json:"answer"`
}
ReplyOptions is one Reply call, an object for the reason SendOptions is one. From is the session replying.
type Result ¶
type Result struct {
Ticket string `json:"ticket"`
Target string `json:"target"`
Status string `json:"status"`
Answer string `json:"answer"`
// Private is set on the outcome of a ticket sent with SendPrivate, which
// only that ticket collects: no note will announce it.
Private bool `json:"private,omitempty"`
}
Result is what a caller gets back from Send or Wait. Answer is empty unless Status is StatusAnswered.
type ScheduleEvent ¶
type ScheduleEvent struct {
ID string `json:"id"`
At int64 `json:"at"`
Prompt string `json:"prompt,omitempty"`
}
ScheduleEvent is the payload of ScheduleEventName: the session whose mark changed, when its prompt is now due, and the prompt. At is 0 and Prompt empty when nothing is waiting anymore.
type SelfOptions ¶
type SelfOptions struct {
From string `json:"from"`
}
SelfOptions is one Self call, an object for the reason SendOptions is one.
type SendOptions ¶
type SendOptions struct {
From string `json:"from"`
Target string `json:"target"`
Project string `json:"project"`
Prompt string `json:"prompt"`
WaitSeconds int `json:"waitSeconds"`
}
SendOptions is one Send, SendPrivate or SendSubagent call. It travels as a single JSON object rather than as positional arguments because a package manager replaces the lich binary under a running backend: a field a newer lich adds is dropped by an older backend, and one an older lich does not send is its zero value, where a positional list refuses both on its count.
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service relays prompts between sessions. Tickets live in memory only: one exists for as long as its errand does, and a lich that restarted has no PTY left to answer into anyway.
func New ¶
New returns a relay reading its roster from sessions, typing through term and announcing what is in flight on events.
func (*Service) AnnounceMerge ¶
AnnounceMerge tells every agent running in checkout that the pull request on its branch was merged from lich's own screen. An agent keeps notes on the work it did there, and without this the last thing they say about it is that it is waiting on a merge, which a later session reads back as true long after the checkout is gone.
Only provider sessions hear it: a terminal card in the same checkout is a shell, where a typed notice would run as a command. A card with no process running has nobody to tell and is skipped, as a parked one is.
Delivery runs in the background and a failure is only logged: the merge it reports already happened, and nothing the caller could do with the error would undo it. The error returned is the workspace failing to load, before anyone was told anything.
func (*Service) Collect ¶
Collect drains every outcome waiting for From, oldest first. With nothing ready and errands still open it holds the line for the next one; with nothing ready and nothing open it returns empty at once. It is the batch half of the nudge: one call picks up what any number of workers produced.
ctx is the caller's: once it is done nothing is drained, because a result handed to a caller that hung up (an interrupted tool call, a killed `lich wait`) is a result nobody reads, and the nudge that would have announced it was skipped for this very collector.
func (*Service) CollectNow ¶
func (s *Service) CollectNow(opts CollectNowOptions) (Collected, error)
CollectNow is Collect without the wait: what is ready and who still owes one, at once. It is how a sender deep in a turn of its own checks in at a decision point, where holding the line would stall the work it is doing.
func (*Service) Focus ¶
func (s *Service) Focus(opts FocusOptions) (Focused, error)
Focus opens the card of the session Target names and brings the window to the front, for an editor that just pointed the person at that session. Target resolves the way Send's does.
func (*Service) Insert ¶
func (s *Service) Insert(opts InsertOptions) (Inserted, error)
Insert pastes Text at the prompt of the session Target names, without sending it. Target resolves the way Send's does. Left empty, Project must name where to look — a project by name, or an absolute directory — and the session is the one live there: the directory of a session itself wins over the root of its project, so an editor open on a worktree reaches the session in that worktree and not one beside it. Two candidates are an error naming both, never a guess.
The text goes in whole or not at all. A session in the middle of a permission prompt is refused: what is typed there is read by the dialog, not the prompt. A person's half-written line is not a reason to refuse; the text is added to the end of it, which is where it was meant to go.
func (*Service) Observe ¶
Observe takes one session-state report from the hooks the provider already runs (docs/hooks/session-state.md). It exists for one case: a target that works through a relayed request and then answers somewhere lich cannot read — its provider's own peer channel, or simply out loud to the person watching. Nothing would ever close that ticket, and the sender would sit out the full wait learning nothing.
A turn ending is only this request's turn when the target has been working since the request arrived. Every provider queues typed input, so a message handed to a busy session is answered a turn later; the ending of the turn already in progress is skipped rather than mistaken for an answer that never came. Getting that backwards would report "answered elsewhere" about a request the target had not read yet, which is worse than saying nothing.
func (*Service) ParkResume ¶
ParkResume parks the continuation of session id's turn, due resumeGrace after resetsAt (unix seconds). Nothing is parked for a reset already past or beyond resumeHorizon, nor over a prompt already parked there: there is one per session, and a person's own outranks lich's.
func (*Service) Peers ¶
func (s *Service) Peers(opts PeersOptions) ([]Peer, error)
Peers lists the live sessions From may address, in the order the sidebar shows them. A session with no PTY running is left out: there is nothing there to type at, and offering it would only produce a message nobody ever reads.
func (*Service) Reply ¶
func (s *Service) Reply(opts ReplyOptions) error
Reply hands an answer back to whoever is waiting on Ticket. It is what the message composed by Send asks the receiving agent to run.
An empty Ticket answers the one errand open against From, the way an empty ticket collects everything waiting for a sender (see Collect). The ticket is written down in one place only — the message typed at the target's prompt — so an agent whose context no longer reaches that message would otherwise be holding an answer with no route home, and the sender blocked on a ticket nobody can name. With two open it is refused: see errandOfLocked.
func (*Service) RunSchedules ¶
func (s *Service) RunSchedules()
RunSchedules types due prompts at their sessions until the process ends, and ages out errands on the same tick (expireTickets). Started once at launch: it holds nothing, so a workspace that never schedules anything pays one read every scheduleTick and nothing else.
func (*Service) Self ¶
func (s *Service) Self(opts SelfOptions) (Peer, error)
Self is the caller's own entry, in the shape Peers lists everybody else's: the one session the roster never shows it. It does not ask whether a process is running there, since the caller asking is that process.
func (*Service) Send ¶
Send types Prompt at the prompt of the session labelled Target and waits for its agent to answer. Project narrows the search when the same label exists in more than one project; empty searches them all. WaitSeconds bounds the wait — 0 uses DefaultWait.
The wait running out is not a failure: the errand is open, and the returned ticket is what picks its outcome up later. A target that is not at a prompt yet is not a failure either — the task is queued and delivered when it is (see queueDelivery). ctx is the caller's: one that hangs up mid-wait hears nothing, and the errand's outcome goes to its inbox as if its wait had run out.
func (*Service) SendPrivate ¶
SendPrivate is Send for a caller that runs inside the sender session without being its agent: a subagent or a workflow step. Every call from that session reaches lich as the session, so this is how the caller keeps its errand to itself — the outcome is collected by its ticket alone, and nothing is typed at the session's prompt or counted on its card about it.
func (*Service) SendSubagent ¶
SendSubagent is Send for a worker opened as the sender's subagent (`lich open --subagent`), so the errand behaves like the subagent it replaces: the report reaches the sender whole where its mod takes it (flushNudge), the errand is not dropped by ticketTTL while the worker lives (sweep), and the sender hears once when the worker blocks on a permission (Observe). It needs a sending session: there is nobody else to report to.
func (*Service) SessionClosed ¶
SessionClosed ends the subagent errands at a session that was just closed by closerID, empty when the window closed it. A caller that closed its own worker (TaskStop runs `lich close` in the caller's process) stopped the work and is told nothing; a caller still holding the line hears stopped, and the ticket stays waitable as stopped. Anyone else's close ends work the caller never stopped, so the stop is filed in the caller's inbox with a nudge, as is one for a caller that is itself a worker somebody waits on (owesSubagentAnswerLocked), whose answer waits for this outcome (WorkerAnswered). The terminal calls this before the process dies (terminal.SetSessionClosed), so the SessionEnd its CLI reports on the way out finds nothing to call unanswered. Errands of any other kind end as they always did. The session's reported state goes too: the same id reopened is a new process that has reported nothing yet.
func (*Service) SessionExited ¶
SessionExited drops what the session's last process reported, once lich has reaped it: a process that dies mid-turn never sends the SessionEnd (idle) that would, so its busy outlived it, and the same id respawned read as busy to every delivery and in every roster until its own process ended a turn. The terminal calls it for a process that ended on its own (terminal.SetSessionExited); a close goes through SessionClosed.
func (*Service) SetPlugins ¶
SetPlugins wires what the relay can ask about the companion plugin. Without it a target that never reacts is indistinguishable from one lich cannot hear, and every relayed message names the command line. Called at startup, before any errand exists.
func (*Service) SetPromptLanguage ¶
SetPromptLanguage wires where the relay reads the language of the text it types at a session. It is read again for every message rather than once, so a change in Settings reaches the next message. Without it the relay speaks English, the default. Called at startup, before any errand exists.
func (*Service) SetRaiseWindow ¶
SetRaiseWindow wires how the relay brings lich's window to the front, or opens one on the session's card when none is open. Nil (a test that does not care) leaves Focus opening the card wherever the window is. Called at startup.
func (*Service) SetWorkerFinished ¶
SetWorkerFinished wires what runs for a worker that finished: it answered its subagent errand and the turn it answered in ended, with no other errand open at it. The app closes the worker there when it shares its caller's checkout (spawn.CloseFinishedWorker). Called at startup, before any errand exists.
func (*Service) Status ¶
Status reads id's errands without collecting anything: an outcome listed as ready stays in the inbox for the agent's own collect. Private tickets are left out of Open and Ready, which no collect of the session reaches.
func (*Service) Wait ¶
Wait blocks on an already-delivered ticket for another round, so a caller whose first wait ran out can come back without sending the message twice. An outcome already sitting in the inbox is handed over on the spot. ctx is the caller's, as in Collect. An errand that ended without an answer and has not had a late one yet answers with how it ended: its ticket is still alive.
func (*Service) WorkerAnswered ¶
WorkerAnswered answers the one subagent errand open at workerID with text, the final message its mod reported, by the same path as Reply. A session with no subagent errand open, or with two, is ignored: the mod cannot tell a worker from a session whose subagents the user kept native, and nothing in the text says which of two errands it answers. An errand answered already keeps its first answer.
A worker still awaiting an outcome of its own (awaitsOutcomeLocked) is ignored too. The mod reports a turn that left nothing in Claude Code's background list, and an errand the worker sent to another session is not in that list, so the text is "I handed it off" rather than the result. The outcome reaching the worker starts the turn whose report is the answer.
func (*Service) WorkerUnanswered ¶
WorkerUnanswered ends the one subagent errand open at workerID as unanswered, the way a turn ending without a reply ends an ordinary errand: its mod reported a turn that left nothing running and had no answer, so nothing else ever would end it while the worker runs. It is ignored where WorkerAnswered is, for an errand that already ended, and for an API error while a usage limit's continuation is parked at the worker, since that continuation is the turn that answers.
The errand stays answerable by its ticket (lapseLocked) and the worker is not finished: its user can still steer it to an answer from its card.
type Sessions ¶
type Sessions interface {
LoadState() ([]store.Project, error)
// SetSessionSchedule clears a scheduled prompt once it has been typed at its
// session (see deliverDue), and parks or drops the continuation of a turn a
// usage limit ended (resume.go). Every other prompt is parked by the window.
SetSessionSchedule(sessionID string, at int64, prompt string) error
// SessionBranch is the branch of the checkout a session runs in, "" when
// git cannot name one. A subagent's report names it (subagentReport).
SessionBranch(sessionID string) string
}
Sessions is the persistence the relay reads: every open session, so a label can be resolved to the session it names and the caller can be told what it may address. The store implements it.
type StalledEvent ¶
type StalledEvent struct {
ID string `json:"id"`
TargetID string `json:"targetId"`
Target string `json:"target"`
}
StalledEvent is the payload of StalledEventName: who asked ("" when the request came from the command line rather than a session), and the session that has whatever was produced.
type Status ¶
type Status struct {
Owed []OwedErrand `json:"owed"`
Open []OpenErrand `json:"open"`
Ready []ReadyErrand `json:"ready"`
}
Status is what a session's mod reads for its status line: the errands it owes an answer to, the ones it handed out that are still open, and the outcomes waiting in its inbox (docs/hooks/mod-status.md). Every list is oldest first and never nil.
type SubagentRoute ¶
type SubagentRoute int
SubagentRoute is where a spawned session's own subagents run, as far as its briefing is concerned.
const ( // RouteSessions is every session whose subagents stay inside its harness and // that may open lich sessions to fan out. RouteSessions SubagentRoute = iota // RouteCards is a Claude Code session whose lich-plugin mod runs a // general-purpose subagent as one of those cards. There the agent's own // Agent tool is the better route (in the background, its report back on its // own, stopped with TaskStop), so the briefing sends it there and keeps // lich's own route for what a subagent cannot be. RouteCards // RouteNative is a Claude Code card whose own subagents stay native, because // it runs as deep as lich nests cards. lich's server instructions still say // a subagent becomes a card in a session with the plugin, so the briefing // says it does not here, and keeps the fan-out under this card rather than // sending it to new sessions, which would nest cards past the limit by // another door. RouteNative )
type Terminal ¶
type Terminal interface {
Live(id string) bool
Ready(id string) bool
// AtPrompt is Ready without minding what the person has typed there: the
// question for a write that does not send (Insert).
AtPrompt(id string) bool
Write(id, data string) error
// QuietFor is how long that session's PTY has produced nothing, which is
// how a delivery knows the target has finished taking the paste in before
// it presses Enter behind it (see awaitSettled).
QuietFor(id string) time.Duration
// AgentName is the name that session's agent answers to in its provider's
// peer roster, read out of the provider's own record. Empty when there is
// none, which is what leaves the roster on the derived name.
AgentName(id string) string
// HoldInput keeps what the person at that session types out of the
// submission this delivery is making, and hands it back at the prompt
// afterwards. The returned release is called once the Enter is through
// (see typeIn).
HoldInput(id string) func()
// SubmitPrompt hands text to the session's Claude Code mod as a prompt of
// its own, submitted as a notification when note is not nil; ErrNoMod when
// no mod polls from that session.
SubmitPrompt(id, text string, note *Notification) (HandedPrompt, error)
// ModAttached is whether a Claude Code mod polls from that session, which
// takes a prompt without touching the line its user is typing.
ModAttached(id string) bool
// ModAnswers is whether that session's mod answers a subagent errand with
// its turn's final message (docs/hooks/mod-answer.md).
ModAnswers(id string) bool
}
Terminal is the PTY side: whether a session has a process running right now, whether what runs in it is the agent rather than the checkout's setup script, and how to type at it. The terminal service implements it.
type WaitOptions ¶
WaitOptions is one Wait call, an object for the reason SendOptions is one.