relay

package
v0.80.0 Latest Latest
Warning

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

Go to latest
Published: Oct 27, 2026 License: AGPL-3.0 Imports: 19 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 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

View Source
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
)
View Source
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.

View Source
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.

View Source
const (
	DirectionOut = "out"
	DirectionIn  = "in"
)

Directions a RelayEvent carries. An empty direction clears the mark: the request it named is over, answered or expired.

View Source
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).

View Source
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.

View Source
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).

View Source
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

View Source
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

func IsRosterName(name, cwd string) bool

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

func IsUnansweredReason(reason string) bool

IsUnansweredReason is whether reason is one the contract names.

func QuotedList

func QuotedList(names []string) string

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

func RosterName(cwd, id string) string

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

func RosterNameOf(kind, recorded, cwd, id string) string

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, 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 = api.CollectNowOptions

type CollectOptions

type CollectOptions = api.CollectOptions

type Collected

type Collected = api.CollectedResults

type Events

type Events interface {
	Emit(name string, data any)
}

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 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

type InboxEvent = api.SessionInbox

type InsertOptions

type InsertOptions = api.InsertTextOptions

type Inserted

type Inserted = api.InsertedText

type Notification

type Notification struct {
	Status  string `json:"status"`
	Summary string `json:"summary"`
}

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 = api.Peer

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
	OK     bool
	Reason string
}

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 = 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

func New(sessions Sessions, term Terminal, events Events) *Service

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

func (s *Service) AgentCheckouts() []string

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

func (s *Service) Collect(ctx context.Context, opts CollectOptions) (Collected, error)

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(_ context.Context, 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(_ context.Context, 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(_ context.Context, 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

func (s *Service) Observe(sessionID, state string)

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

func (s *Service) ParkResume(id string, resetsAt int64)

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(_ context.Context, 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(_ context.Context, opts ReplyOptions) (api.None, 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(ctx context.Context, 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

func (s *Service) Send(ctx context.Context, opts SendOptions) (Result, error)

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

func (s *Service) SendPrivate(ctx context.Context, opts SendOptions) (Result, error)

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

func (s *Service) SendSubagent(ctx context.Context, opts SendOptions) (Result, error)

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

func (s *Service) SessionClosed(sessionID, closerID string)

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

func (s *Service) SessionExited(sessionID string)

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

func (s *Service) SetPlugins(plugins Plugins)

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

func (s *Service) SetPromptLanguage(lang func() prompt.Lang)

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

func (s *Service) SetRaiseWindow(raise func(sessionID string))

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

func (s *Service) SetWorkerFinished(fn func(workerID string) error)

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

func (s *Service) Status(id string) 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) Submit added in v0.74.0

func (s *Service) Submit(ctx context.Context, opts api.SubmitOptions) (api.None, error)

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 mod takes it where one is attached, 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) Wait

func (s *Service) Wait(ctx context.Context, opts WaitOptions) (Result, error)

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

func (s *Service) WorkerAnswered(workerID, text string)

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

func (s *Service) WorkerUnanswered(workerID, reason string)

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(_ 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). 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 = api.RelayStalled

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(_ 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
	// 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 its agent is at a prompt, and how to type at it. The terminal service implements it.

type WaitOptions

type WaitOptions = api.WaitOptions

Jump to

Keyboard shortcuts

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