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 chat where it is drawn as one, 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 EnvelopeLine(message string) (string, bool)
- func HandoffEnvelope(from, session, note string) string
- func IsRosterName(name, cwd string) bool
- func QuotedList(names []string) string
- func RosterName(cwd, id string) string
- func RosterNameOf(kind, recorded, cwd, id string) string
- func SpawnBriefing(lang prompt.Lang, hasTools bool, route SubagentRoute) string
- type Attr
- type CollectNowOptions
- type CollectOptions
- type Collected
- type Element
- type Envelope
- type Events
- type FocusEvent
- type FocusOptions
- type Focused
- type HandedPrompt
- type InboxEvent
- type InsertOptions
- type Inserted
- type Item
- type Peer
- type PeersOptions
- type Plugins
- type PromptReceipt
- type RelayEvent
- type ReplyOptions
- type Result
- type ScheduleEvent
- type SelfOptions
- type SendOptions
- type Service
- func (s *Service) AgentCheckouts() []string
- func (s *Service) AnnounceMerge(ctx context.Context, opts api.AnnounceMergeOptions) (api.None, error)
- func (s *Service) Collect(ctx context.Context, opts CollectOptions) (Collected, error)
- func (s *Service) CollectNow(_ context.Context, opts CollectNowOptions) (Collected, error)
- func (s *Service) ErrandOpen(ticket string) bool
- func (s *Service) Focus(_ context.Context, opts FocusOptions) (Focused, error)
- func (s *Service) Focused(ctx context.Context, _ api.None) (Focused, error)
- func (s *Service) HandSubagent(ctx context.Context, opts SendOptions) (Result, error)
- func (s *Service) Insert(ctx context.Context, opts InsertOptions) (Inserted, error)
- func (s *Service) Observe(sessionID, state string)
- func (s *Service) ObserveTool(sessionID, tool, detail string)
- func (s *Service) ParkResume(id string, resetsAt int64)
- func (s *Service) Peers(_ context.Context, opts PeersOptions) ([]Peer, error)
- func (s *Service) ReadPullRequest(read api.PRRead)
- func (s *Service) Reply(_ context.Context, opts ReplyOptions) (api.None, error)
- func (s *Service) Request(ctx context.Context, opts api.RequestOptions) (api.None, error)
- func (s *Service) ResumeNow(id string)
- func (s *Service) RunSchedules()
- func (s *Service) ScheduleSelf(_ context.Context, opts api.ScheduleSelfOptions) (api.None, error)
- func (s *Service) Self(ctx context.Context, 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) SetSchedule(_ context.Context, opts api.SetScheduleOptions) (api.None, error)
- func (s *Service) SetShown(_ context.Context, opts ShownSessionOptions) (api.None, error)
- func (s *Service) SetWindowAttached(attached func() bool)
- func (s *Service) SetWorkerFinished(fn func(workerID string) error)
- func (s *Service) Submit(ctx context.Context, opts api.SubmitOptions) (api.None, error)
- func (s *Service) Touched(req api.TouchedRequest) string
- func (s *Service) UserTyped(sessionID string)
- func (s *Service) Wait(ctx context.Context, opts WaitOptions) (Result, error)
- func (s *Service) WatchesCheckout(checkout string) bool
- type Sessions
- type ShownSessionOptions
- type StalledEvent
- type SubagentRoute
- type Terminal
- type WaitOptions
Constants ¶
const ( KindTask = "task" KindWorkerFinished = "worker-finished" KindWorkerFailed = "worker-failed" KindWorkerStopped = "worker-stopped" KindWorkerWaiting = "worker-waiting" KindExpired = "expired" KindMerged = "merged" KindNotice = "notice" KindRequest = "request" )
The kinds an envelope is.
const ( TopicChecksFailed = "checks-failed" TopicChecksPassed = "checks-passed" TopicReview = "review" TopicScheduled = "scheduled" TopicUsageReset = "usage-reset" TopicCompacted = "compacted" TopicUnanswered = "unanswered" TopicLoop = "loop" TopicHandoff = "handoff" TopicEditOverlap = "edit-overlap" )
The topics a notice carries.
const ( AnswerLastMessage = "last-message" AnswerReply = "reply" )
How a task's answer is taken.
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 // PromptLimit bounds one relayed prompt. The message is typed into a TUI a // character at a time; a megabyte of it is a hang, not a prompt. PromptLimit = 8192 )
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" // ToolSend and ToolList are named here for the ping-pong breaker, which // reads a turn that only called relay tools as one that did no work. ToolSend = "send_to_session" ToolList = "list_sessions" )
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 ( PromptDelivered = "delivered" // queued behind the turn running, which has not ended yet PromptAcked = "acked" // the turn carrying it started PromptEnded = "ended" // the chat exited first )
How far a prompt handed to a chat got.
const BriefingEnv = "LICH_BRIEFING"
BriefingEnv carries the spawn briefing to a provider whose agent config prints it from a hook (Kiro CLI).
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).
Variables ¶
var ErrNoChat = errors.New("this session is not drawn as a chat")
ErrNoChat is what Terminal.ChatPrompt answers for a session not drawn as a chat, which takes its messages typed at its prompt.
Functions ¶
func EnvelopeLine ¶
EnvelopeLine is the one line an envelope means, for where a conversation is named by its first message: a request's summary, a task's prompt, else what its first child says. False for a message that is no envelope.
func HandoffEnvelope ¶
HandoffEnvelope is the note a session hands its successor: a notice and not a task, since nothing is owed back to a session done with the work. note is HandoffNote filled in; its first paragraph is the summary, the rest the prompt.
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 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 name rather than resolving one: internal/terminal, which hands it to a Claude Code fork.
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 every provider that is never handed a roster name.
Claude Code with nothing recorded answers to no name lich can know: it is born without --name (terminal.nameArgs), names itself after its directory and a random suffix, and writes that name nowhere lich reads. Empty says so, where a derived name would be a second name for one session that its own roster never shows.
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: 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.
The artifact sentence is here, and not only in lich's MCP instructions, because it competes with the harness's own way of publishing a page: Claude Code's system prompt sends the agent to a hosted artifact, and Codex and Kiro CLI never read the MCP instructions at all. It names the variable rather than the folder, which the MCP instructions spell out, so the argv stays the same for every session. No single quote either: Codex takes this inside one (internal/terminal, codexBriefingArgs).
Types ¶
type CollectNowOptions ¶
type CollectNowOptions = api.CollectNowOptions
type CollectOptions ¶
type CollectOptions = api.CollectOptions
type Collected ¶
type Collected = api.CollectedResults
type Envelope ¶
type Envelope struct {
Kind string
Topic string
From string
Session string
Ticket string
Answer string
Truncated int
PR int
Issue int
Branch string
Base string
URL string
Image string
Title string
Body []Element
// Items are a request's rows, written before its prompt.
Items []Item
}
Envelope is one notification. Empty attributes are left out, and Body is written in order, each element's text verbatim.
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 = api.SessionFocus
type FocusOptions ¶
type FocusOptions = api.FocusSessionOptions
type Focused ¶
type Focused = api.FocusedSession
type HandedPrompt ¶
type HandedPrompt struct {
Await func(context.Context) PromptReceipt
}
HandedPrompt is a prompt queued for a session's chat. Await waits for the turn carrying it to start until ctx ends, and says how far it got.
type InboxEvent ¶
type InboxEvent = api.SessionInbox
type InsertOptions ¶
type InsertOptions = api.InsertTextOptions
type Inserted ¶
type Inserted = api.InsertedText
type Item ¶
Item is one <item> of a request: its attributes in order, empty ones left out, and its text, self-closing when there is none.
type PeersOptions ¶
type PeersOptions = api.PeersOptions
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 ¶
type PromptReceipt struct {
State string
}
PromptReceipt is what became of one prompt handed to a chat.
type RelayEvent ¶
type RelayEvent = api.SessionRelay
type ReplyOptions ¶
type ReplyOptions = api.ReplyOptions
type Result ¶
type Result = api.SendResult
type ScheduleEvent ¶
type ScheduleEvent = api.SessionSchedule
type SelfOptions ¶
type SelfOptions = api.SelfOptions
type SendOptions ¶
type SendOptions = api.SendOptions
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) AgentCheckouts ¶ added in v0.79.0
AgentCheckouts is every checkout a live provider session runs in, each once: the ones the pull request watch (internal/project) reads every tick, since a pull request opens and merges there with no window looking. A workspace that fails to load follows none until the next call.
func (*Service) AnnounceMerge ¶
func (s *Service) AnnounceMerge(ctx context.Context, opts api.AnnounceMergeOptions) (api.None, error)
AnnounceMerge tells every agent running in opts.Checkout that the pull request on its branch was merged, from lich's own screen or, as the pull request watch finds, anywhere else (internal/project, branchpr.go). A merge already announced is not announced again. 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. The session that opened one of those agents hears it too, wherever it runs: it handed the work out and keeps the same kind of notes on it.
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 ¶
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) ErrandOpen ¶
ErrandOpen is whether errand ticket is still waiting on its worker's answer.
func (*Service) Focus ¶
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) Focused ¶ added in v0.83.0
Focused names the session whose card is on screen, for a caller that acts on whatever the person is looking at.
func (*Service) HandSubagent ¶
HandSubagent is SendSubagent that waits for nothing: the errand is opened and its task handed over, or held until the worker is at a prompt, and the ticket comes back at once, its outcome reaching the asker as an envelope. /subagent answers in the time a hook waits, long before any worker could.
func (*Service) Insert ¶
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) ObserveTool ¶ added in v0.87.0
ObserveTool takes the tool a session's PreToolUse reported, for the breaker to tell a turn that worked from one that only messaged. Work by either side ends a streak: a coordinator's own turns run only relay tools, and what its worker did comes home in a reply, which is not a hop.
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 ¶
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) ReadPullRequest ¶ added in v0.87.0
ReadPullRequest checks every watch in the read's checkout against it.
func (*Service) Reply ¶
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) Request ¶
Request words opts as a request envelope in the prompt language and submits it to the session as Submit does.
func (*Service) ResumeNow ¶ added in v0.87.0
ResumeNow makes session id's continuation due at once: the person moved it to a profile with quota left. It takes the row the reset's continuation sits on, so there is one continuation either way and it is typed once the session is back at its prompt. A prompt the person parked there stays and goes out at its own time.
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) ScheduleSelf ¶ added in v0.87.0
ScheduleSelf is an agent's trigger for the session it runs in. What the person set there outranks it.
func (*Service) Self ¶
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 chat 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. 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) SetSchedule ¶ added in v0.87.0
SetSchedule is the person's trigger for a session. It replaces whatever the session holds, whoever set it.
func (*Service) SetShown ¶ added in v0.83.0
SetShown records the session whose card the window has on screen.
func (*Service) SetWindowAttached ¶ added in v0.83.0
SetWindowAttached wires whether a native window is connected: a card shown by a window that has gone is not on screen. 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) Submit ¶ added in v0.74.0
Submit types opts.Message at a session's prompt and sends it, as the person at that session would, with no ticket and no answer to wait for: the window's pull request handoffs, which open a session on the problem they name. Its chat takes it where it is drawn as one, as every ticketless delivery does.
Only a provider session takes one: at a shell's prompt the Enter would run the message as a command. A session not running yet is refused, so a caller opening one waits for its prompt first. opts.Message is sanitized the way a relayed prompt is: it carries text strangers wrote (an issue body, a comment), and an ESC[201~ in it would close the paste and type the rest as keys.
func (*Service) Touched ¶
func (s *Service) Touched(req api.TouchedRequest) string
Touched answers a /session-touched call (docs/hooks/session-touched.md): the edit-overlap notes for its session, "" when there is nothing to say. A held touch records and answers nothing; its note waits for the next answer.
func (*Service) UserTyped ¶ added in v0.87.0
UserTyped ends every streak a session is part of: a person sending a line there has stepped into the exchange.
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) WatchesCheckout ¶ added in v0.87.0
WatchesCheckout is whether any open session in checkout holds a watch, which is what makes its pull request worth the extra read.
type Sessions ¶
type Sessions interface {
LoadState(_ context.Context, _ api.None) ([]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), and takes the person's own (schedule.go).
SetSessionSchedule(sessionID string, at int64, prompt string) error
// SetLichSchedule is SetSessionSchedule for the continuation lich parks
// (resume.go): the row remembers it is lich's.
SetLichSchedule(sessionID string, at int64, prompt string) error
// SetAgentSchedule is SetSessionSchedule for a prompt an agent parked on its
// own session.
SetAgentSchedule(sessionID string, at int64, prompt string) error
// SetSessionWatch writes a session's watch as it now stands (watch.go).
SetSessionWatch(sessionID string, w api.SessionWatch) 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 ShownSessionOptions ¶ added in v0.83.0
type ShownSessionOptions = api.ShownSessionOptions
type StalledEvent ¶
type StalledEvent = api.RelayStalled
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 session whose provider's lich-plugin hook asks /subagent, // which runs a subagent as one of those cards (an exploration type the // provider keeps native stays inside the session). 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 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(_ context.Context, opts api.SessionIDOptions) (bool, error)
// Reachable is Live or a chat running: whether a message can reach the
// session at all. Live stays the question before a typed write, which a
// chat cannot take.
Reachable(_ context.Context, opts api.SessionIDOptions) (bool, error)
Ready(_ context.Context, opts api.SessionIDOptions) (bool, error)
// 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(_ context.Context, opts api.WriteOptions) (api.None, 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
// Status is the last session-status report the window was sent for that
// session, zero when there is none: where the roster reads the tool and
// the reason the card shows.
Status(id string) api.SessionStatus
// 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()
// ChatPrompt hands text to the session's chat as its next message;
// ErrNoChat when that session is not drawn as one.
ChatPrompt(id, text string) (HandedPrompt, error)
// ChatOpened is whether that session's chat has opened its conversation,
// which takes a prompt without touching anything its user is typing.
ChatOpened(id string) bool
// Chat is whether that session is drawn as a chat, which takes a message
// whole as its next user message (docs/hooks/notification.md, Delivery).
Chat(id string) bool
// FinalMessage is the final message of that session's last turn, whole,
// and whether lich can read one for it at all: its chat driver, or its
// provider's transcript in a terminal.
FinalMessage(id string) (string, bool)
}
Terminal is the PTY side: whether a session has a process running right now, whether its agent is at a prompt, and how to type at it. The terminal service implements it.
type WaitOptions ¶
type WaitOptions = api.WaitOptions