agy

package
v0.173.2 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2026 License: Apache-2.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 agy manages Antigravity CLI (agy) agent sessions: their inbox, stream-json runner and PreInvocation hook for mid-turn message delivery.

Index

Constants

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

View Source
const (
	EnvAgent = "BEEKEEPER_AGY_AGENT"
	EnvName  = "BEEKEEPER_AGENT_NAME"
)

The environment beekeeper starts an agy agent with: its start id and its roster name.

View Source
const Comm = "agy"

Comm is the agy binary's process name.

View Source
const Harness = "agy"

Harness is the harness name agy sessions carry (claude.Session.Harness).

View Source
const HostPrefix = "agy_"

HostPrefix makes a start id the agent's host session id on the roster: agy_<start id>.

Variables

View Source
var ErrNotRunning = errors.New("no agy process reads its inbox")

ErrNotRunning is a message to an agent whose inbox no process reads.

Functions

func AgentConvPath

func AgentConvPath(stateDir, id string) string

AgentConvPath maps an agent start id to the agy conversationId its init event announced.

func Confirm

func Confirm(path string) error

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

func ConvLinkPath(stateDir, convID string) string

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 Discover

func Discover(brainDir, stateDir string, t *proc.Table, now time.Time) []*claude.Session

Discover returns the running agy sessions, newest first.

func Drain

func Drain(path string) ([]string, error)

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

func Ended(brainDir string, running []*claude.Session, since time.Time) []*claude.Session

Ended returns the agy sessions written to since since that no running session runs, most recently active first.

func Follow

func Follow(path string, n int) ([]claude.Turn, error)

Follow is Tail with the model's tool calls among the turns, as claude.Follow returns them.

func InboxPath

func InboxPath(stateDir, id string) string

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

func MakeInbox(path string) error

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

func ParseModelsOutput(raw string) []string

ParseModelsOutput extracts the model selector IDs from the stdout of `agy models`, ignoring spinner carriage-return frames and headers.

func PreInvocation

func PreInvocation(stateDir string, raw []byte) []byte

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

func ProjectForDir(projectsDir, dir string) string

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

func RemoveInbox(path string) (removed bool, err error)

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

func ResolveInbox(stateDir, convID string) string

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

func Run(ctx context.Context, inbox, logPath string, argv []string, stderr io.Writer) error

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.

func Send

func Send(path, msg string) error

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

func StreamPath(stateDir, id string) string

StreamPath is the stream-json event log of the agent started under id.

func Tail

func Tail(path string, n int) ([]claude.Turn, error)

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

func TranscriptPath(brainDir, convID string) string

TranscriptPath is the transcript.jsonl path of the conversation convID under brainDir.

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.

Jump to

Keyboard shortcuts

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