agentgit

package
v2.33.3 Latest Latest
Warning

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

Go to latest
Published: May 13, 2026 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Overview

Package agentgit provides a WebSocket-based service for watching git repository changes on the agent. It is mounted at /api/v0/git/watch and allows clients to subscribe to file paths, triggering scans of the corresponding git repositories.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ExtractChatContext

func ExtractChatContext(r *http.Request) (chatID uuid.UUID, ancestorIDs []uuid.UUID, ok bool)

ExtractChatContext reads chat identity headers from the request. Returns zero values if headers are absent (non-chat request).

Types

type API

type API struct {
	// contains filtered or unexported fields
}

API exposes the git watch HTTP routes for the agent.

func NewAPI

func NewAPI(logger slog.Logger, pathStore *PathStore, opts ...Option) *API

NewAPI creates a new git watch API.

func (*API) Routes

func (a *API) Routes() http.Handler

Routes returns the chi router for mounting at /api/v0/git.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler manages per-connection git watch state.

func NewHandler

func NewHandler(logger slog.Logger, opts ...Option) *Handler

NewHandler creates a new git watch handler.

func (*Handler) RequestScan

func (h *Handler) RequestScan()

RequestScan pokes the scan trigger so the run loop performs a scan.

func (*Handler) RunLoop

func (h *Handler) RunLoop(ctx context.Context, scanFn func())

RunLoop runs the main event loop that listens for refresh requests and fallback poll ticks. It calls scanFn whenever a scan should happen (rate-limited to scanCooldown). It blocks until ctx is canceled.

func (*Handler) Scan

Scan performs a scan of all subscribed repos and computes deltas against the previously emitted snapshots.

func (*Handler) Subscribe

func (h *Handler) Subscribe(paths []string) bool

Subscribe processes a subscribe message, resolving paths to git repo roots and adding new repos to the watch set. Returns true if any new repo roots were added.

type Option

type Option func(*Handler)

Option configures the git watch service.

func WithClock

func WithClock(c quartz.Clock) Option

WithClock sets a controllable clock for testing. Defaults to quartz.NewReal().

func WithGitBinary

func WithGitBinary(path string) Option

WithGitBinary overrides the git binary path (for testing).

type PathStore

type PathStore struct {
	// contains filtered or unexported fields
}

PathStore tracks which file paths each chat has touched. It is safe for concurrent use.

func NewPathStore

func NewPathStore() *PathStore

NewPathStore creates a new PathStore.

func (*PathStore) AddPaths

func (ps *PathStore) AddPaths(chatIDs []uuid.UUID, paths []string)

AddPaths adds paths to every chat in chatIDs and notifies their subscribers. Zero-value UUIDs are silently skipped.

func (*PathStore) GetPaths

func (ps *PathStore) GetPaths(chatID uuid.UUID) []string

GetPaths returns all paths tracked for a chat, deduplicated and sorted lexicographically.

func (*PathStore) Len

func (ps *PathStore) Len() int

Len returns the number of chat IDs that have tracked paths.

func (*PathStore) Notify

func (ps *PathStore) Notify(chatIDs []uuid.UUID)

Notify sends a signal to all subscribers of the given chat IDs without adding any paths. Zero-value UUIDs are silently skipped.

func (*PathStore) Subscribe

func (ps *PathStore) Subscribe(chatID uuid.UUID) (<-chan struct{}, func())

Subscribe returns a channel that receives a signal whenever paths change for chatID, along with an unsubscribe function that removes the channel.

Jump to

Keyboard shortcuts

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