Documentation
¶
Overview ¶
Package agy manages Antigravity CLI (agy) agent sessions: their inbox, stream-json runner and PreInvocation hook for mid-turn message delivery.
Index ¶
- Constants
- Variables
- func AgentConvPath(stateDir, id string) string
- func Confirm(path string) error
- func ConvLinkPath(stateDir, convID string) string
- func Discover(brainDir, stateDir string, t *proc.Table, now time.Time) []*claude.Session
- func Drain(path string) ([]string, error)
- func Ended(brainDir string, running []*claude.Session, since time.Time) []*claude.Session
- func Follow(path string, n int) ([]claude.Turn, error)
- func InboxPath(stateDir, id string) string
- func MakeInbox(path string) error
- func ParseModelsOutput(raw string) []string
- func PreInvocation(stateDir string, raw []byte) []byte
- func ProjectForDir(projectsDir, dir string) string
- func QuotaPath(stateDir, id string) string
- func ReadConv(stateDir, id string) string
- func ReadTranscript(path string, now time.Time, sessionCwd ...string) (claude.Work, claude.Activity)
- func RemoveInbox(path string) (removed bool, err error)
- func ResolveInbox(stateDir, convID string) string
- func Run(ctx context.Context, inbox, logPath string, argv []string, stderr io.Writer) error
- func Send(path, msg string) error
- func SpendTranscripts(brainDir string, from, to time.Time) []claude.SpendTranscript
- func StreamPath(stateDir, id string) string
- func Tail(path string, n int) ([]claude.Turn, error)
- func TranscriptPath(brainDir, convID string) string
- func WriteQuotaError(inbox string, qerr *QuotaError) error
- type InjectedStep
- type PreInvocationArgs
- type PreInvocationResult
- type QueuedMessage
- type QuotaError
Constants ¶
const ( StateBusy = "busy" StateIdle = "idle" StateEnded = "ended" )
The session states: busy while a turn runs, idle while it waits for a message, ended when no process runs the session.
const ( EnvAgent = "BEEKEEPER_AGY_AGENT" EnvName = "BEEKEEPER_AGENT_NAME" )
The environment beekeeper starts an agy agent with: its start id and its roster name.
const Comm = "agy"
Comm is the agy binary's process name.
const Harness = "agy"
Harness is the harness name agy sessions carry (claude.Session.Harness).
const HostPrefix = "agy_"
HostPrefix makes a start id the agent's host session id on the roster: agy_<start id>.
Variables ¶
var ErrNotRunning = errors.New("no agy process reads its inbox")
ErrNotRunning is a message to an agent whose inbox no process reads.
var IdleGrace = 200 * time.Millisecond
IdleGrace is how long an idle runner waits after its session parks, finishes or leaves the roster before closing its inbox FIFO and exiting.
Functions ¶
func AgentConvPath ¶
AgentConvPath maps an agent start id to the agy conversationId its init event announced.
func Confirm ¶
Confirm records that agy accepted one user_input step on the stream for the inbox at path, confirming the corresponding Inflight or head Injected message and recording its ID in Delivered.
func ConvLinkPath ¶
ConvLinkPath maps an agy conversationId to the inbox path of the session running that conversation, so the PreInvocation hook can drain the inbox by conversationId from its stdin.
func Drain ¶
Drain marks all pending messages in the persistent inbox at path inflight in Injected (keeping any unconfirmed Injected messages ahead of newly queued Messages, deduplicated by message ID) and returns their texts in FIFO order. Drained messages remain in Injected on disk until confirmed by Confirm (on a stream user_input event) or by appearing in the conversation's transcript.
func Ended ¶
Ended returns the agy sessions written to since since that no running session runs, most recently active first.
func Follow ¶
Follow is Tail with the model's tool calls among the turns, as claude.Follow returns them.
func InboxPath ¶
InboxPath is the inbox FIFO of the agent started under id, in beekeeper's state folder. Beside it live <inbox>.lock and <inbox>.queue.
func MakeInbox ¶
MakeInbox creates the inbox FIFO at path, keeping one that exists. Any persistent queue file beside it (<path>.queue) is preserved so unread messages survive a session restart.
func ParseModelsOutput ¶
ParseModelsOutput extracts the model selector IDs from the stdout of `agy models`, ignoring spinner carriage-return frames and headers.
func PreInvocation ¶
PreInvocation marks the queued messages of the session named in raw (a PreInvocation hook stdin payload) inflight in its persistent queue and formats them as an injectSteps JSON response. Messages remain inflight on disk until confirmed by the stream or transcript so a killed or timed-out hook or an agy crash before storing the step re-injects or restores them without message loss or duplicate delivery.
func ProjectForDir ¶
ProjectForDir searches projectsDir (*.json in sorted filename order) for an Antigravity project whose resource folderUri or gitFolder.folderUri matches "file://" + dir, returning its project id or "".
func QuotaPath ¶
QuotaPath is the quota error marker written when an agy session started under id stops on a quota 429 / RESOURCE_EXHAUSTED error.
func ReadConv ¶
ReadConv returns the conversationId for an agent start id from its .conv link file or from the init event in its stream log.
func ReadTranscript ¶
func ReadTranscript(path string, now time.Time, sessionCwd ...string) (claude.Work, claude.Activity)
ReadTranscript reads an agy transcript's window for the issues and repositories it acts on and its activity: turns, tool calls and errors, GitHub CLI calls, token counts, context and model requests for pricing.
func RemoveInbox ¶
RemoveInbox removes the inbox FIFO at path, its queue, its lock file and its conversation link; removed is false when none of them existed.
func ResolveInbox ¶
ResolveInbox finds the inbox path for a session by its agy conversationId (from PreInvocation's stdin) or its BEEKEEPER_AGY_AGENT environment variable.
func Run ¶
Run executes argv (an `agy --input-format stream-json --output-format stream-json` command) with its stream output appended to logPath and its turns fed from the persistent inbox at inbox.
While agy is idle (after its init event or after a turn's result event), Run pops the next queued message from inbox into Inflight and writes it as a stream-json user event to agy's stdin. While a turn is running, Run does not write to agy's stdin: queued messages stay in the persistent queue for the PreInvocation hook to drain into Injected before the next model call inside the running turn, and each user_input step_update event confirms the corresponding Inflight or Injected message. Any Injected messages that were not confirmed before the turn ends (e.g. a hook killed or timed out on the final model call) are restored to Messages on result and sent on stdin as the next turn.
When agy reports a quota 429 / RESOURCE_EXHAUSTED error on stderr or in a stream event (including mid-turn when agy stays alive waiting on stdin), Run records the quota error beside inbox, terminates the agy process and returns *QuotaError.
func Send ¶
Send queues msg in the persistent inbox at path with a unique message ID and wakes the runner on the FIFO. When no process holds the FIFO open for reading, Send returns ErrNotRunning without queuing msg.
func SpendTranscripts ¶
func SpendTranscripts(brainDir string, from, to time.Time) []claude.SpendTranscript
SpendTranscripts reads the requests from from up to to of every agy transcript under brainDir. A file last written before from is skipped; transcript_full.jsonl is skipped so requests are not double-counted.
func StreamPath ¶
StreamPath is the stream-json event log of the agent started under id.
func Tail ¶
Tail returns the last n turns of an agy transcript: user messages and the model's text responses, without thinking, tool calls or tool results.
func TranscriptPath ¶
TranscriptPath is the transcript.jsonl path of the conversation convID under brainDir.
func WriteQuotaError ¶
func WriteQuotaError(inbox string, qerr *QuotaError) error
WriteQuotaError persists qerr beside inbox (<id>.quota.json) so the starter, doctor and supervisor can see that the session stopped on a quota error.
Types ¶
type InjectedStep ¶
type InjectedStep struct {
UserMessage string `json:"userMessage"`
}
InjectedStep is one step injected before an agy model call.
type PreInvocationArgs ¶
type PreInvocationArgs struct {
ConversationID string `json:"conversationId"`
TranscriptPath string `json:"transcriptPath"`
InvocationNum int `json:"invocationNum"`
}
PreInvocationArgs are the fields beekeeper hook preinvocation reads from agy's PreInvocation stdin payload.
type PreInvocationResult ¶
type PreInvocationResult struct {
InjectSteps []InjectedStep `json:"injectSteps,omitempty"`
}
PreInvocationResult is the JSON payload beekeeper hook preinvocation writes to stdout when queued messages are injected into a running turn.
type QueuedMessage ¶
type QueuedMessage struct {
ID string `json:"id"`
Text string `json:"text"`
InputSeq int `json:"inputSeq,omitempty"`
}
QueuedMessage is one message in an agy session's persistent inbox, carrying a unique ID so at-least-once delivery across retries and restarts can deduplicate messages and deliver each one in FIFO order once.
type QuotaError ¶
type QuotaError struct {
ShortError string `json:"shortError"`
Status string `json:"status,omitempty"`
ErrorCode int `json:"errorCode,omitempty"`
ResetsIn time.Duration `json:"resetsIn,omitempty"`
At time.Time `json:"at,omitzero"`
Model string `json:"model,omitempty"`
}
QuotaError records a quota 429 / RESOURCE_EXHAUSTED failure reported by agy on stderr or in its stream-json output.
func ParseQuotaError ¶
func ParseQuotaError(line string) *QuotaError
ParseQuotaError parses an agy stderr or stream error line for a quota 429 / RESOURCE_EXHAUSTED error, returning nil when line is not a quota error.
func ReadQuotaError ¶
func ReadQuotaError(stateDir, id string) *QuotaError
ReadQuotaError reads the persisted QuotaError for the agy agent id under stateDir, or returns nil when none exists.
func ReadQuotaErrorForInbox ¶
func ReadQuotaErrorForInbox(inboxOrLog string) *QuotaError
ReadQuotaErrorForInbox reads the persisted QuotaError beside an inbox or stream log path, or returns nil when none exists.
func (*QuotaError) Error ¶
func (e *QuotaError) Error() string