Documentation
¶
Overview ¶
Package client provides access to the current user's AHT agent-session state.
By default, a Client uses the local realtime broker when it is available and falls back to the durable registry for one-shot operations. Config.Mode can instead require realtime or durable storage; invalid modes make operations fail with ErrInvalidMode. Use Client.Watch when a program needs an initial snapshot followed by live state revisions.
Index ¶
- Constants
- Variables
- func IsUnavailable(err error) bool
- type Activity
- type Client
- func (c *Client) GC(ctx context.Context, deleteAfter time.Duration) (registry.GCResult, error)
- func (c *Client) Get(ctx context.Context, id string) (registry.Session, error)
- func (c *Client) List(ctx context.Context, filter registry.Filter) ([]registry.Session, error)
- func (c *Client) Mode() Mode
- func (c *Client) Observe(ctx context.Context, observation registry.Observation) (registry.Session, error)
- func (c *Client) ObserveBatch(ctx context.Context, observations []registry.Observation) ([]registry.Session, error)
- func (c *Client) Ping(ctx context.Context) error
- func (c *Client) Realtime() *broker.Client
- func (c *Client) SocketPath() string
- func (c *Client) StorePath() string
- func (c *Client) Subscribe(ctx context.Context, filter registry.Filter) (*broker.Subscription, error)
- func (c *Client) Summary(ctx context.Context, filter registry.Filter) ([]registry.Summary, error)
- func (c *Client) SummaryByTmuxSession(ctx context.Context, filter registry.Filter) ([]registry.Summary, error)
- func (c *Client) SummaryByTmuxSessionWithOptions(ctx context.Context, options registry.SummaryOptions) ([]registry.Summary, error)
- func (c *Client) Watch(ctx context.Context, filter registry.Filter, ...) error
- type Config
- type Filter
- type Harness
- type Mode
- type MultiplexerContext
- type Observation
- type OperationError
- type Presence
- type Session
- type StateSnapshot
- type Subscription
- type Summary
- type TmuxContext
Examples ¶
Constants ¶
const ( // ModeAuto routes operations through the realtime broker and falls back to // the durable registry on disk when the broker is offline. // This is the default mode. ModeAuto Mode = "auto" // ModeRealtimeOnly directs all operations strictly to the realtime broker socket. // When the broker is offline, operations fail immediately with [ErrUnavailable] // without reading disk or taking filesystem locks. ModeRealtimeOnly Mode = "realtime" // ModeDurableOnly directs all operations directly to the on-disk registry file, // bypassing the realtime broker entirely. ModeDurableOnly Mode = "durable" PresenceLive Presence = registry.PresenceLive PresenceGone Presence = registry.PresenceGone PresenceUnknown Presence = registry.PresenceUnknown ActivityRunning Activity = registry.ActivityRunning ActivityWaiting Activity = registry.ActivityWaiting ActivityIdle Activity = registry.ActivityIdle ActivityFailed Activity = registry.ActivityFailed ActivityInterrupted Activity = registry.ActivityInterrupted ActivityUnknown Activity = registry.ActivityUnknown HarnessClaude Harness = registry.HarnessClaude HarnessCodex Harness = registry.HarnessCodex HarnessCursor Harness = registry.HarnessCursor HarnessCopilot Harness = registry.HarnessCopilot HarnessCline Harness = registry.HarnessCline HarnessKimiCode Harness = registry.HarnessKimiCode HarnessGrok Harness = registry.HarnessGrok HarnessGoose Harness = registry.HarnessGoose HarnessPi Harness = registry.HarnessPi HarnessOmp Harness = registry.HarnessOmp HarnessOpenCode Harness = registry.HarnessOpenCode HarnessAgy Harness = registry.HarnessAgy HarnessKilo Harness = registry.HarnessKilo HarnessDroid Harness = registry.HarnessDroid HarnessOpenClaw Harness = registry.HarnessOpenClaw HarnessHermes Harness = registry.HarnessHermes )
Variables ¶
var ( ErrUnavailable = errors.New("aht broker unavailable") // ErrProtocol means the broker returned an invalid or incompatible response. ErrProtocol = errors.New("aht broker protocol error") ErrRealtimeRequired = errors.New("operation requires a realtime broker connection") // ErrInvalidMode means a client was configured with an unsupported Mode. ErrInvalidMode = errors.New("invalid aht client mode") )
Functions ¶
func IsUnavailable ¶
IsUnavailable reports whether err means that no realtime broker accepted the connection.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client reads and updates agent-harness state through the local AHT broker. Depending on Mode, operations route to the realtime broker socket, durable disk storage, or auto-fallback between the two.
func New ¶
New returns a client for the configured local AHT instance. An unsupported Mode makes all operations return ErrInvalidMode without performing I/O.
func (*Client) List ¶
List returns all sessions matching filter.
Example ¶
package main
import (
"context"
"fmt"
"os"
"path/filepath"
"time"
"github.com/zigai/aht/pkg/client"
"github.com/zigai/aht/pkg/registry"
)
func main() {
directory, err := os.MkdirTemp("", "aht-client-example")
if err != nil {
panic(err)
}
defer func() { _ = os.RemoveAll(directory) }()
storePath := filepath.Join(directory, "sessions.json")
presence := registry.PresenceLive
activity := registry.ActivityRunning
if _, err := registry.NewFileStore(storePath).Observe(context.Background(), registry.Observation{
Source: registry.ObservationSourceNative,
Evidence: registry.ObservationEvidenceNativeEvent,
Harness: registry.HarnessCodex,
Identity: registry.ObservationIdentity{SessionID: "example"},
Presence: &presence,
Activity: &activity,
ObservedAt: time.Now().UTC(),
}); err != nil {
panic(err)
}
aht := client.New(client.Config{
StorePath: storePath,
SocketPath: filepath.Join(directory, "offline.sock"),
})
sessions, err := aht.List(
context.Background(),
client.Filter{Presence: client.PresenceLive},
)
if err != nil {
panic(err)
}
fmt.Printf("%s: %s\n", sessions[0].Harness, *sessions[0].Activity)
}
Output: codex: running
func (*Client) Observe ¶
func (c *Client) Observe(ctx context.Context, observation registry.Observation) (registry.Session, error)
Observe records one agent-harness observation using the configured Mode. Only ModeAuto falls back to durable storage when the broker is unavailable.
func (*Client) ObserveBatch ¶
func (c *Client) ObserveBatch(ctx context.Context, observations []registry.Observation) ([]registry.Session, error)
ObserveBatch atomically records a group of agent-harness observations.
func (*Client) Realtime ¶ added in v1.3.0
Realtime returns the underlying realtime broker socket client.
func (*Client) SocketPath ¶
SocketPath returns the broker endpoint used by the client.
func (*Client) Subscribe ¶ added in v1.3.0
func (c *Client) Subscribe(ctx context.Context, filter registry.Filter) (*broker.Subscription, error)
Subscribe returns an active subscription streaming state snapshots from the broker. Subscribe requires a running broker and is not supported in ModeDurableOnly.
func (*Client) Summary ¶
Summary returns aggregate session counts grouped by terminal-multiplexer session.
func (*Client) SummaryByTmuxSession ¶
func (c *Client) SummaryByTmuxSession(ctx context.Context, filter registry.Filter) ([]registry.Summary, error)
SummaryByTmuxSession implements registry.Store.
func (*Client) SummaryByTmuxSessionWithOptions ¶
func (c *Client) SummaryByTmuxSessionWithOptions(ctx context.Context, options registry.SummaryOptions) ([]registry.Summary, error)
SummaryByTmuxSessionWithOptions implements registry.Store.
type Config ¶
Config identifies the local AHT instance used by a Client. Empty fields use the current user's default registry and its associated broker socket.
type Filter ¶ added in v1.3.0
Filter specifies matching criteria when querying or watching sessions.
type Mode ¶ added in v1.3.0
type Mode string
Mode controls how a Client routes operations between the realtime broker and the durable registry file on disk.
type MultiplexerContext ¶ added in v1.3.0
type MultiplexerContext = registry.MultiplexerContext
MultiplexerContext represents the unified multiplexer location of a session.
type Observation ¶ added in v1.3.0
type Observation = registry.Observation
Observation represents an observation recorded for a session.
type OperationError ¶
OperationError is a machine-readable failure returned by the AHT broker.
func (*OperationError) Error ¶
func (e *OperationError) Error() string
type Presence ¶ added in v1.3.0
Presence indicates whether an agent session is live, gone, or unknown.
type StateSnapshot ¶ added in v1.3.0
type StateSnapshot = registry.StateSnapshot
StateSnapshot is a revisioned collection of tracked sessions.
type Subscription ¶ added in v1.3.0
type Subscription = broker.Subscription
Subscription streams independently owned snapshots from the realtime broker.
type TmuxContext ¶ added in v1.3.0
type TmuxContext = registry.TmuxContext
TmuxContext represents the tmux multiplexer location of a session.