Documentation
¶
Overview ¶
Package projects is the Code Loop engine: it watches GitHub repositories, project boards and Discussions boards for ready issues and runs CLI jobs on them through the gh-fix and gh-discuss skills.
Index ¶
- Constants
- Variables
- func ApplyBrowserSources(w *Engine, driver *browser.Browser, options BrowserOptions, gh GHCLI) *browser.SignInRecovery
- func ExpandTarget(value string) (string, error)
- func GitHubSignIn(ctx context.Context, config browser.Config, out io.Writer, ...) (string, error)
- func GitHubSignedIn(ctx context.Context, config browser.Config) (string, error)
- func ImportBrowserProfile(from string, config browser.Config) error
- func OpenBrowserWindow(ctx context.Context, config browser.Config, out io.Writer) error
- func OriginTarget() (string, bool)
- func ResolveDelivery(mode string, interval time.Duration, intervalSet bool, options BrowserOptions) (string, time.Duration, error)
- func SignInFlow() browser.SignIn
- type AgentIdentifier
- type AgentOutputRunner
- type AgentRunner
- type AgentSession
- type AviaryAgentRun
- type AviaryAgentRunner
- type BrowserOptions
- type CommandRunner
- func (r CommandRunner) AgentName() string
- func (r CommandRunner) AgentNameFor(target string) string
- func (r CommandRunner) Run(ctx context.Context, issue Issue) error
- func (r CommandRunner) RunSession(ctx context.Context, issue Issue, session AgentSession, ...) error
- func (r CommandRunner) RunSessionWithOutput(ctx context.Context, issue Issue, session AgentSession, ...) error
- func (r CommandRunner) RunWithOutput(ctx context.Context, issue Issue, output io.Writer) error
- type Comment
- type CommentClient
- type CommentKind
- type CommentLister
- type CommentPoster
- type CommentReactor
- type Discussion
- type DiscussionSource
- type Engine
- func (w *Engine) ApplySettings(ctx context.Context, update SettingsUpdate) (SettingsSnapshot, error)
- func (w *Engine) ClearClones(context.Context) (core.ClearClonesResult, error)
- func (w *Engine) CloneRoot() (string, error)
- func (w *Engine) CloneRoots() []string
- func (w *Engine) CreateIssue(ctx context.Context, request core.IssueCreate) (core.IssueCreateResult, error)
- func (w *Engine) CurrentSettings(ctx context.Context) (SettingsSnapshot, error)
- func (w *Engine) ListClones(ctx context.Context) (core.ClonesSnapshot, error)
- func (w *Engine) PostIssueUpdate(ctx context.Context, update core.IssueUpdate) (core.IssueUpdateResult, error)
- func (w *Engine) Run(ctx context.Context) error
- func (w *Engine) SetTempDirs(dirs []string)
- func (w *Engine) SetUnblockAgent(config unblockConfig)
- func (w *Engine) SetUnblockInterval(interval time.Duration)
- func (w *Engine) TempDirs() []string
- func (w *Engine) TriggerUnblock(key string) error
- func (w *Engine) UnblockInterval() time.Duration
- type EngineSnapshot
- type ForkSource
- type GHCLI
- func (g GHCLI) AddReaction(ctx context.Context, repo string, commentID int64, content string) error
- func (g GHCLI) AddReviewCommentReaction(ctx context.Context, repo string, commentID int64, content string) error
- func (g GHCLI) AddReviewReaction(ctx context.Context, repo string, nodeID string, content string) error
- func (g GHCLI) ClosingIssues(ctx context.Context, repo string, number int) ([]int, error)
- func (g GHCLI) ConfigureWebhook(ctx context.Context, value, endpoint, secret string) ([]string, error)
- func (g GHCLI) ForkFor(ctx context.Context, repo string) (string, error)
- func (g GHCLI) HydrateIssue(ctx context.Context, repo string, issue *Issue) error
- func (g GHCLI) IssueAuthor(ctx context.Context, repo string, number int) (string, error)
- func (g GHCLI) ListComments(ctx context.Context, repo string, number int) ([]Comment, error)
- func (g GHCLI) ListIssues(ctx context.Context, repo string) ([]Issue, error)
- func (g GHCLI) ListReviewComments(ctx context.Context, repo string, number int) ([]Comment, error)
- func (g GHCLI) ListUnansweredDiscussions(ctx context.Context, repo string) ([]Discussion, error)
- func (g GHCLI) OriginatingWorkState(ctx context.Context, repo string, number int) (OriginatingWorkState, error)
- func (g GHCLI) PostComment(ctx context.Context, repo string, number int, body string) error
- func (g GHCLI) PostCommentURL(ctx context.Context, repo string, number int, body string) (string, error)
- func (g GHCLI) PostCommentWithAttachments(ctx context.Context, repo string, number int, body string, files []string) (string, error)
- func (g GHCLI) ProjectState(ctx context.Context, repo string) (string, error)
- func (g GHCLI) RecentComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
- func (g GHCLI) RecentReviewComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
- func (g GHCLI) Run(ctx context.Context, args ...string) ([]byte, error)
- func (g GHCLI) SetIssueStatus(ctx context.Context, repo string, issue Issue, status string) error
- func (g GHCLI) StacksEnabled(ctx context.Context, repo string) (bool, error)
- type Identity
- type Issue
- type IssueDependency
- type IssueHydrator
- type IssueLabel
- type IssueSource
- type IssueStatuser
- type JobSnapshot
- type LogSource
- type Manager
- func (m *Manager) AddWatch(watch Watch) error
- func (m *Manager) ChatContext(ctx context.Context, project string) string
- func (m *Manager) Checkpoint(context.Context, saferestart.Marker) error
- func (m *Manager) CloneClear(ctx context.Context) (core.ClearClonesResult, error)
- func (m *Manager) CloneList(ctx context.Context) (core.ClonesSnapshot, error)
- func (m *Manager) ExplainJob(target string, number int) (map[string]any, error)
- func (m *Manager) GetJob(target string, number, lines, events int) (map[string]any, error)
- func (m *Manager) GitHubSession() core.GitHubSession
- func (m *Manager) GitHubSignIn() (map[string]any, error)
- func (m *Manager) HoldNewJobs(hold bool)
- func (m *Manager) Identity() string
- func (m *Manager) ImportBrowserProfile(from string) (map[string]any, error)
- func (m *Manager) InFlightJobs(target string) []int
- func (m *Manager) IssueComment(ctx context.Context, repository string, number int, text string, ...) (map[string]any, error)
- func (m *Manager) IssueCreate(ctx context.Context, repository, text, model string, attachments []string) (map[string]any, error)
- func (m *Manager) JobAction(ctx context.Context, action, target string, number int) (map[string]any, error)
- func (m *Manager) ListJobs(targets []string, status string, states []string, query string, ...) map[string]any
- func (m *Manager) Log(line string)
- func (m *Manager) Reconcile(cfg *config.Config)
- func (m *Manager) Refresh(target string) (map[string]any, error)
- func (m *Manager) RemoveWatch(target string) bool
- func (m *Manager) ResumeAfterRestart(marker saferestart.Marker)
- func (m *Manager) RunProjectTask(ctx context.Context, run scheduler.ProjectRun) (string, error)
- func (m *Manager) RunningJobs() []saferestart.Job
- func (m *Manager) ScheduledRetry(target string, number int) (string, error)
- func (m *Manager) SetAviaryAgentRunner(run AviaryAgentRunner)
- func (m *Manager) SetBrowser(cfg config.BrowserConfig)
- func (m *Manager) SetEngineEnabled(enabled bool)
- func (m *Manager) SetLogSource(source LogSource)
- func (m *Manager) SetMentionRouter(route MentionRouter)
- func (m *Manager) SetReportDelivery(deliver ReportDelivery)
- func (m *Manager) SetUsageRecorder(record UsageRecorder)
- func (m *Manager) Shutdown()
- func (m *Manager) Snapshot(snapshot core.Snapshot)
- func (m *Manager) Status(_ context.Context, logOffset int, targets []string) map[string]any
- func (m *Manager) Transcript(target string, number int) []transcript.Event
- func (m *Manager) UnblockRun(target string, number int) (map[string]any, error)
- type MentionRouter
- type MentionSource
- type OriginatingWorkState
- type ProjectStateSource
- type PullRequestWorkState
- type RecentComment
- type ReportDelivery
- type ReviewCommentLister
- type ReviewMentionSource
- type ReviewReactor
- type SessionAgentOutputRunner
- type SessionAgentRunner
- type SettingsSnapshot
- type SettingsUpdate
- type StackSource
- type StatusCLI
- type TargetAgentIdentifier
- type UIReporter
- type UsageRecorder
- type Watch
- type WebhookEvent
- type WebhookHandler
- type WorkClosureChecker
Constants ¶
const ( DeliveryBrowser = "browser" DeliveryWebhook = "webhook" DeliveryPoll = "poll" )
The ways Code Loop reads GitHub. Browser is the default: it reads the rendered pages in Aviary's own browser, signed in as the user, which costs no API rate limit. Webhook and poll are the API-backed modes.
const BrowserInterval = browser.DefaultWatchInterval
BrowserInterval is how often browser delivery reloads its pages by default.
const UsageAgentID = "projects"
UsageAgentID is the agent ID Code Loop job usage is recorded under.
Variables ¶
var ErrNotWatching = errors.New("no projects are being watched; add one with project_add or aviary watch")
ErrNotWatching is returned by calls that need a running engine when no project is watched.
Functions ¶
func ApplyBrowserSources ¶
func ApplyBrowserSources(w *Engine, driver *browser.Browser, options BrowserOptions, gh GHCLI) *browser.SignInRecovery
ApplyBrowserSources swaps the engine's GitHub reads for their browser-backed equivalents: issue lists from the rendered issues page, boards from the rendered Projects page with the board's own Status column, and the comments the handoff reads from the rendered conversation. Writes (comments, status moves) and Discussions stay on gh.
Newly seen candidates are hydrated with their body and dependency state through gh, once per issue for the run. A signed-out read is recorded for the board's banner instead of opening a window, and the returned recovery is what the banner's "Sign in to GitHub" calls.
func ExpandTarget ¶
ExpandTarget resolves a target as `aviary watch` accepts it, expanding the projects: and discussions: shorthands against the current checkout's origin remote.
func GitHubSignIn ¶
func GitHubSignIn(ctx context.Context, config browser.Config, out io.Writer, timeout time.Duration) (string, error)
GitHubSignIn opens a visible window on the profile at GitHub's sign-in page and waits until the profile is signed in, returning the login.
func GitHubSignedIn ¶
GitHubSignedIn reports the GitHub login Aviary's browser profile is signed in as, or an empty string when it is signed out. It reads headlessly, so asking never puts a window on screen.
func ImportBrowserProfile ¶
ImportBrowserProfile copies the GitHub sign-in saved in a profile signed in elsewhere into the configured profile, for machines where no sign-in window can appear.
func OpenBrowserWindow ¶
OpenBrowserWindow opens Aviary's browser visibly on its profile, with nothing attached, so its settings (and its GitHub sign-in) can be changed. It blocks until the window is closed.
func OriginTarget ¶
OriginTarget is the current checkout's origin GitHub repository.
func ResolveDelivery ¶
func ResolveDelivery(mode string, interval time.Duration, intervalSet bool, options BrowserOptions) (string, time.Duration, error)
ResolveDelivery validates a delivery mode and settles the poll interval it runs at. An empty mode is browser delivery, and browser delivery reloads every BrowserInterval unless an interval was set explicitly.
func SignInFlow ¶
SignInFlow is the visible sign-in window a signed-out run opens when the user asks.
Types ¶
type AgentIdentifier ¶
type AgentIdentifier interface {
AgentName() string
}
AgentIdentifier picks the agent for a new job.
type AgentOutputRunner ¶
AgentOutputRunner runs a coding agent on an issue, copying its output.
type AgentRunner ¶
AgentRunner runs a coding agent on an issue.
type AgentSession ¶
type AgentSession struct {
ID string
Agent string
CheckoutDirectory string
Resume bool
// ReusedClone marks CheckoutDirectory as a clone an earlier job left that
// this fresh run was handed and must not clone again (#622).
ReusedClone bool
// RunDir is the sanctioned temp directory a run without a checkout starts
// in and clones under, chosen once per run by CommandRunner.
RunDir string
// Update carries a change made to the issue while the agent was working
// it. A resumed session that has one is prompted with it
// instead of the generic "continue", so the closure, edited description,
// or new comment reaches the agent that is already holding the work
// rather than being noticed only after the run ends.
Update string
// Model overrides the model an in-process agent (an aviary/<agent> spec)
// runs the turn with, as a scheduled run's model override does; empty
// runs it with the agent's own.
Model string
}
AgentSession is the coding-agent session a job runs in.
type AviaryAgentRun ¶
type AviaryAgentRun struct {
// Agent names the Aviary agent: the model of an aviary/<agent> spec.
Agent string
// Model overrides the agent's default model for the turn; empty uses it.
Model string
// Prompt is the turn's message.
Prompt string
// MediaURL is an image the turn sees, for a vision call.
MediaURL string
// Workdir is granted to the agent's file tools and exec for the turn,
// such as a job's clone.
Workdir string
// Event receives each event of the turn's stream.
Event func(agent.StreamEvent)
// Hold holds the turn's new tool calls while engaged, such as during the
// shutdown checkpoint.
Hold *agent.TurnHold
}
AviaryAgentRun is one turn an in-process agent definition, such as the built-in aviary agent, runs on one of Aviary's own agents.
type AviaryAgentRunner ¶
type AviaryAgentRunner func(ctx context.Context, run AviaryAgentRun) error
AviaryAgentRunner runs one turn through core's agent runner and returns once it ends, with the error it ended on. Cancelling ctx stops the turn.
type BrowserOptions ¶
type BrowserOptions struct {
// Binary and Profile come from Aviary's browser settings, so Code Loop
// reads GitHub through the same browser and profile as Aviary itself.
Binary string
Profile string
// Vision enables the opt-in, capped screenshot fallback for pages the
// DOM extractor stops recognising.
Vision bool
// Headed drives a visible browser instead of a headless one, so the pages
// being read can be watched. It is a debugging switch.
Headed bool
}
BrowserOptions decide which browser browser delivery drives and how.
func BrowserOptionsFrom ¶
func BrowserOptionsFrom(settings config.BrowserConfig) BrowserOptions
BrowserOptionsFrom builds the options from Aviary's browser settings.
func (BrowserOptions) Config ¶
func (o BrowserOptions) Config() browser.Config
Config converts the options into the launcher's configuration.
type CommandRunner ¶
type CommandRunner struct {
Binary, CodexBinary, ClaudeBinary string
// Agents holds every configured agent spec (agent/model:level) to load
// balance across when dispatching new issues. AgentName rotates through it
// round robin.
Agents []string
Agent, Repo string
Identity Identity
Output io.Writer
// Approval is the Code Loop surface's effective approval mode, which
// every CLI launch renders through its definition.
Approval clidefs.ApprovalMode
NoMerge bool
// NoChangelog asks the dispatched /gh-fix prompt to skip adding a
// changelog entry for the run, mirroring how NoMerge asks it to leave the
// pull request unmerged.
NoChangelog bool
// AllowedCommenters are the GitHub logins whose comments steer the run.
// The prompt names them, because the agent reads the issue thread itself
// and would otherwise take instructions from anyone who comments.
AllowedCommenters []string
// RemoteControl asks Claude to start its Remote Control bridge so a headless
// run is viewable from the Claude mobile app and claude.ai/code. Claude does
// not honour the request under -p (see remoteControlSettings), so it is off
// by default. It affects Claude runs only; see codexRemoteControlNotice for
// why Codex runs stay local.
RemoteControl bool
// Definitions is the agent registry this runner renders invocations from.
// A nil registry falls back to the run's own, which is the built-in
// definitions until a config file replaces them.
Definitions *clidefs.Registry
// TargetAgents is each target's own agent specs, in fallback order:
// a job on that target runs on the first agent whose quota is not used
// up. A target without an entry load balances across Agents.
TargetAgents map[string][]string
// Quotas reports the latest quota reading of each agent, keyed by agent
// name, so dispatch skips an agent with none left. Nil skips nothing.
Quotas func() map[string]string
// Active tracks the agents this runner has started and their checkouts,
// for the shutdown checkpoint. It is shared by pointer across
// copies, and nil tracks nothing.
Active *activeAgents
// Transcripts records each run's raw output and structured events. Nil
// records nothing.
Transcripts *transcriptStore
// CloneRoot picks the sanctioned temp directory a run without a checkout
// starts in and clones under. Nil uses the system temp
// directory.
CloneRoot func() (string, error)
// Aviary runs in-process agent definitions through core's agent runner.
// Nil fails their dispatch.
Aviary AviaryAgentRunner
// RecordUsage receives each run's token use for core usage tracking. Nil
// records nothing.
RecordUsage UsageRecorder
// contains filtered or unexported fields
}
CommandRunner runs jobs on CLI processes, rendering each run's argv from the agent definitions.
func (CommandRunner) AgentName ¶
func (r CommandRunner) AgentName() string
AgentName returns the agent spec (agent/model:level) to use for the next newly dispatched issue, rotating round robin through Agents when more than one is configured so work is load balanced evenly across concurrency.
func (CommandRunner) AgentNameFor ¶
func (r CommandRunner) AgentNameFor(target string) string
AgentNameFor returns the agent spec for a new job on target. A target with its own agents takes the first one whose quota is not used up; any other target load balances across Agents, skipping agents with no quota left. When every candidate is out of quota the first one is used anyway, so work is never silently dropped.
func (CommandRunner) Run ¶
func (r CommandRunner) Run(ctx context.Context, issue Issue) error
Run runs a coding agent on issue.
func (CommandRunner) RunSession ¶
func (r CommandRunner) RunSession(ctx context.Context, issue Issue, session AgentSession, updateSession func(AgentSession)) error
RunSession runs a coding agent on issue in session.
func (CommandRunner) RunSessionWithOutput ¶
func (r CommandRunner) RunSessionWithOutput(ctx context.Context, issue Issue, session AgentSession, updateSession func(AgentSession), output io.Writer) error
RunSessionWithOutput runs a coding agent on issue in session, copying its output.
func (CommandRunner) RunWithOutput ¶
RunWithOutput runs a coding agent on issue, copying its output.
type CommentClient ¶
type CommentClient = core.CommentClient
CommentClient posts and lists comments.
type CommentKind ¶
type CommentKind int
CommentKind names which of GitHub's comment APIs a comment belongs to. Each has its own IDs, listings, webhook deliveries, and reaction endpoint.
const ( // ConversationComment is an ordinary comment on an issue or on a pull // request's conversation tab. ConversationComment CommentKind = iota // ReviewComment is an inline comment on a pull request's diff (issue // #695). ReviewComment // ReviewBody is the body of a submitted pull request review. ReviewBody )
type CommentReactor ¶
type CommentReactor = core.CommentReactor
CommentReactor reacts to issue comments.
type Discussion ¶
Discussion is a top-level GitHub Discussion thread that has not yet received any reply.
type DiscussionSource ¶
type DiscussionSource interface {
ListUnansweredDiscussions(context.Context, string) ([]Discussion, error)
}
DiscussionSource lists the Discussion threads that have no reply yet.
type Engine ¶
type Engine struct {
Repo string
Targets []string
Interval time.Duration
UseWebhooks bool
WebUIURL string
Events <-chan WebhookEvent
Concurrency int
StatePath string
ReadyState string
Issues IssueSource
// Discussions lists unanswered top-level Discussion threads for
// Discussions-board targets. When nil, Discussions-board targets are
// never polled.
Discussions DiscussionSource
Runner AgentRunner
// RecordUsage receives the Code Loop usage the engine observes: each job
// run's wall time and each issue's merged or failed outcome. Nil records
// nothing.
RecordUsage UsageRecorder
// RouteMention hands a prompt to the built-in Code Loop agent. A direct
// mention on a finished or paused job goes to it instead of restarting
// the job; nil restarts the job as before.
RouteMention func(ctx context.Context, prompt string) error
// Active is the shutdown checkpoint's record of active runs (issue
// #741). The runner records runs whose agent is running; the run loop
// adds runs waiting out a scheduled wakeup, which have a checkout but no
// agent process. Nil records nothing.
Active *activeAgents
Out io.Writer
// Projects supplies the push-mode project board fingerprint. When nil,
// board changes are only picked up by the fallback poll.
Projects ProjectStateSource
Status IssueStatuser
UI UIReporter
// Registry is the agent registry this run was configured with. The
// settings API reports the agents it holds, so the dashboard's agent
// selector offers a config-defined agent without a code change. A nil
// registry falls back to the run's own.
Registry *clidefs.Registry
Quota func(context.Context) map[string]string
// Identity names this instance in cooperative handoff comments. It is
// generated once at startup and never persisted.
Identity Identity
// AllowedCommenters restricts which GitHub logins may trigger a direct
// @/aviary:ID mention run, and whose new comments are relayed
// into a running agent. An empty list places no restriction;
// the CLI defaults it to the authenticated gh user.
AllowedCommenters []string
// SelfLogin is the GitHub login this instance runs as. A new comment from
// an allowed commenter that mentions it triggers a recheck of its issue
//. Empty turns that trigger off.
SelfLogin string
// Comments drives the cooperative handoff handshake. When
// nil, ownership negotiation is skipped and dispatch behaves as before.
Comments CommentClient
// Mentions is scanned on every poll for direct @/aviary:ID mentions when
// no webhook delivers them, on an issue and on its pull request alike
//. Nil leaves mentions to the webhook path alone.
Mentions MentionSource
// Webhooks re-reconciles push webhooks on every periodic poll so a
// repository that joins a project board after startup gets a webhook
// without a restart. Nil skips reconciliation, as in poll
// mode where no webhooks are configured at all.
Webhooks func(context.Context)
// WebhookOnline reports whether push deliveries are reaching the webhook
// server, such as whether the ngrok tunnel was alive at its last check
//. Nil reports push mode as always online.
WebhookOnline func() bool
// Recover re-establishes the run's own long-lived connections after the
// machine wakes from sleep, such as browser mode's browser.
// Nil has nothing to recover.
Recover func(context.Context)
// GitHubSession reports browser delivery's GitHub sign-in, which the
// board shows as a signed-out banner. Nil outside browser delivery.
GitHubSession func() core.GitHubSession
// Held reports whether a safe restart is holding new jobs. While it is,
// polls dispatch nothing and leave waiting jobs as they are; running jobs
// carry on. Nil never holds.
Held func() bool
// RestartNotice returns, once, the notice a safe restart left for the job
// it stopped on issue, or "" when it stopped none there. The resumed
// session is prompted with it. Nil has no notices.
RestartNotice func(Issue) string
// Transcripts holds every job's structured transcript.
Transcripts *transcriptStore
// contains filtered or unexported fields
}
Engine is the Code Loop engine: it watches targets for ready issues, claims them, and runs coding-agent jobs on them up to a concurrency limit.
func (*Engine) ApplySettings ¶
func (w *Engine) ApplySettings(ctx context.Context, update SettingsUpdate) (SettingsSnapshot, error)
ApplySettings validates and applies update, returning the resulting settings snapshot. It hands the update to the running Run loop, which owns the mutated fields, so it only takes effect once Run is looping. An update that changes nothing is a read, answered from CurrentSettings without waiting on the loop at all.
func (*Engine) ClearClones ¶
ClearClones removes every clone nothing can still need.
func (*Engine) CloneRoot ¶
CloneRoot picks the directory a new run's agent starts in and clones under: the first sanctioned root with room for a clone.
func (*Engine) CloneRoots ¶
CloneRoots reports the sanctioned directories, in the order new clones try them.
func (*Engine) CreateIssue ¶
func (w *Engine) CreateIssue(ctx context.Context, request core.IssueCreate) (core.IssueCreateResult, error)
CreateIssue files an issue on a repository through the gh-create skill , run by the prompt agent with this instance's identity so the issue carries gh-create's created-by marker. A non-empty model overrides the configured prompt-agent model for this call. It waits for the skill to finish and reports the new issue's URL.
A request identical to one still filing joins it, and one identical to an issue filed within filedIssueMemory gets that issue back, so a caller that gave up waiting and asks again never files a duplicate (issue #710). The filing outlives a caller that stops waiting.
func (*Engine) CurrentSettings ¶
func (w *Engine) CurrentSettings(ctx context.Context) (SettingsSnapshot, error)
CurrentSettings reports the live settings snapshot without changing anything. It reads the snapshot the Run loop last published rather than asking the loop, which may be in the middle of a poll, so the settings modal renders immediately. Before Run has published one, nothing has changed the settings yet, so they are read as configured.
func (*Engine) ListClones ¶
ListClones enumerates every recorded clone with its size, adopting leftovers found on disk first.
func (*Engine) PostIssueUpdate ¶
func (w *Engine) PostIssueUpdate(ctx context.Context, update core.IssueUpdate) (core.IssueUpdateResult, error)
PostIssueUpdate posts update as a comment on its issue or pull request that mentions the author and this instance, the way the stuck-job watchdog's unblock agent reaches a job: aviary's mention path delivers it to the owning job. It reports the comment's URL.
func (*Engine) SetTempDirs ¶
SetTempDirs replaces the ordered temp directories new clones are placed in.
func (*Engine) SetUnblockAgent ¶
func (w *Engine) SetUnblockAgent(config unblockConfig)
SetUnblockAgent sets the unblock call's agent and model override.
func (*Engine) SetUnblockInterval ¶
SetUnblockInterval changes the watchdog's interval, restarting its wait so the new interval takes effect at once.
func (*Engine) TempDirs ¶
TempDirs reports the configured temp directories, empty for the system temp directory.
func (*Engine) TriggerUnblock ¶
TriggerUnblock asks the watchdog for an unblock round now, over every stuck job or, given a job key, over that job alone. It never waits: the round runs on the watchdog's goroutine and logs what it finds and does, as a timed round does.
func (*Engine) UnblockInterval ¶
UnblockInterval is how often the watchdog runs, or 0 when it is off.
type EngineSnapshot ¶
EngineSnapshot is the engine's published state.
type ForkSource ¶
type ForkSource = core.ForkSource
ForkSource names the fork pull requests come from when a repository is not writable.
type GHCLI ¶
type GHCLI struct {
Binary string
Filter string
AllIssues bool
ReadyState string
// Timeout bounds each `gh` call; zero uses ghCommandTimeout. Interactive
// callers that must answer quickly set a shorter one.
Timeout time.Duration
// contains filtered or unexported fields
}
GHCLI reads and writes GitHub through the gh CLI, and the public REST API for public repositories.
func (GHCLI) AddReaction ¶
AddReaction adds an emoji reaction to a specific comment, used to acknowledge a direct mention was read.
func (GHCLI) AddReviewCommentReaction ¶
func (g GHCLI) AddReviewCommentReaction(ctx context.Context, repo string, commentID int64, content string) error
AddReviewCommentReaction adds an emoji reaction to an inline pull request review comment, acknowledging a direct mention posted in one.
func (GHCLI) AddReviewReaction ¶
func (g GHCLI) AddReviewReaction(ctx context.Context, repo string, nodeID string, content string) error
AddReviewReaction adds an emoji reaction to the body of a submitted pull request review, named by its GraphQL node ID. content uses the REST spelling, such as "eyes".
func (GHCLI) ClosingIssues ¶
ClosingIssues reads repo#number and, when it is a pull request, returns the issues its description closes.
func (GHCLI) ConfigureWebhook ¶
func (g GHCLI) ConfigureWebhook(ctx context.Context, value, endpoint, secret string) ([]string, error)
ConfigureWebhook ensures every webhook the target needs exists, and reports the names of the ones it had to create. Existing webhooks pointing at the endpoint are left untouched, so calling this repeatedly against the same target is safe.
func (GHCLI) ForkFor ¶
ForkFor reports where a fix for an issue in repo is pushed: an empty string when the authenticated user can push to repo, and otherwise the OWNER/REPO of the user's fork of it. GitHub's create-fork call returns the existing fork when there already is one, so it doubles as the lookup.
func (GHCLI) HydrateIssue ¶
HydrateIssue fills in the dispatch-only fields a browser-mode extraction cannot read off the rendered issues page: the issue body, its creation time, and its dependency/sub-issue state. It is deliberately the smallest fetch that answers those questions -- one REST `GET /repos/:repo/issues/:number` plus the dependency lookup loadDependencies already performs -- and it goes through apiGETObject, so a public repository is read on the unauthenticated API and spends none of the token's rate limit. No GraphQL query is issued.
Callers are responsible for the request budget: the browser package.s issue source calls this once per newly seen dispatch candidate, never per tick and never for the whole list.
func (GHCLI) IssueAuthor ¶
IssueAuthor reads who opened repo#number. The issues endpoint answers for pull requests too, since every pull request is also an issue.
func (GHCLI) ListComments ¶
ListComments lists the comments on an issue or pull request.
func (GHCLI) ListIssues ¶
ListIssues lists the dispatchable issues of a target.
func (GHCLI) ListReviewComments ¶
ListReviewComments lists the inline review comments and submitted review bodies on pull request repo#number, oldest first.
func (GHCLI) ListUnansweredDiscussions ¶
ListUnansweredDiscussions lists top-level Discussion threads that have not received any reply yet. A discussion's own reply count doubles as the record of whether it still needs an answer, so no local state is needed to avoid re-dispatching an already-answered thread.
This is one of only three GraphQL calls left in aviary; GitHub Discussions has no REST API at all, so it is unavoidable. It only runs for repositories explicitly configured with a `discussions:` target, never as part of ordinary issue-repo polling.
func (GHCLI) OriginatingWorkState ¶
func (g GHCLI) OriginatingWorkState(ctx context.Context, repo string, number int) (OriginatingWorkState, error)
OriginatingWorkState reads the state of an issue and the pull requests that work on it.
func (GHCLI) PostComment ¶
PostComment posts a comment on an issue or pull request.
func (GHCLI) PostCommentURL ¶
func (g GHCLI) PostCommentURL(ctx context.Context, repo string, number int, body string) (string, error)
PostCommentURL posts body on repo#number and reports the comment's URL.
func (GHCLI) PostCommentWithAttachments ¶ added in v0.7.6
func (g GHCLI) PostCommentWithAttachments(ctx context.Context, repo string, number int, body string, files []string) (string, error)
PostCommentWithAttachments posts body on repo#number with files uploaded and embedded through gh's --attach, and reports the comment's URL.
func (GHCLI) ProjectState ¶
ProjectState returns a fingerprint of a project board's dispatchable state. It fetches only item IDs, statuses, and issue identities, skipping the issue bodies, labels, and the per-issue dependency lookups a dispatching poll performs, so push mode can check an idle board cheaply and often.
func (GHCLI) RecentComments ¶
func (g GHCLI) RecentComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
RecentComments lists repo's issue and pull request comments updated since the given time through the repository-wide comment listing, so a whole repository costs one request per scan however many issues it has.
func (GHCLI) RecentReviewComments ¶
func (g GHCLI) RecentReviewComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
RecentReviewComments lists the inline review comments and submitted review bodies posted on repo's open pull requests since the given time (issue #695). Inline comments have a repository-wide listing like conversation comments do. Reviews have none, so they are read from each open pull request updated since then, which submitting a review counts as.
func (GHCLI) Run ¶
Run runs gh with args and returns its standard output. A failure's error carries whatever gh printed, so callers can show its message.
func (GHCLI) SetIssueStatus ¶
SetIssueStatus moves an issue's board items to status.
type Identity ¶
type Identity string
Identity uniquely names one aviary instance. It is the instance ID kept in Aviary's state, so a restarted instance recognizes its own prior claims; ownership claimed by other instances is still renegotiated.
type IssueDependency ¶
type IssueDependency = core.IssueDependency
IssueDependency is an issue an issue is blocked by.
type IssueHydrator ¶
IssueHydrator reads one issue back from GitHub with its state and dependencies, so paused work whose issue the poll does not list can still be woken when its blockers close.
type IssueStatuser ¶
IssueStatuser moves an issue's board item to a status.
type JobSnapshot ¶
type JobSnapshot = core.JobSnapshot
JobSnapshot and EngineSnapshot live in package core so the API and later dashboards render the same published state.
type LogSource ¶
LogSource pages core's log ring: the lines component logged after offset, oldest first, and the offset to ask from next time. An offset of zero or less asks for the latest limit lines; a limit of zero or less asks for every line.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns the Code Loop engine inside the Aviary server. It builds the engine from the projects every agent in aviary.yaml owns plus any runtime watches, applies changed settings to the running engine, and restarts it when a change needs a new one, such as a new target.
func NewManager ¶
NewManager returns a manager that keeps its work state and job transcripts under stateDir.
func (*Manager) ChatContext ¶
ChatContext is the context the Code Loop agent gets with each request: this instance, its targets, the board the chat was opened from when project is set, and a live snapshot of issue and job counts and per-job summaries, read now.
func (*Manager) Checkpoint ¶
Checkpoint commits and pushes every running job's work and stops the engine. The work state keeps each job's session, so the jobs resume in the same sessions once Aviary is back.
func (*Manager) CloneClear ¶
CloneClear is project_clone_clear.
func (*Manager) ExplainJob ¶
ExplainJob is project_job_explain: why a job is where it is and what moves it on.
func (*Manager) GetJob ¶
GetJob is project_job_get: one job's state, session, transcript events and scrollback. lines and events limit the scrollback lines and transcript events returned; 0 uses the defaults and a negative value returns all.
func (*Manager) GitHubSession ¶
func (m *Manager) GitHubSession() core.GitHubSession
GitHubSession reports browser delivery's GitHub sign-in, the zero session when GitHub is read some other way.
func (*Manager) GitHubSignIn ¶
GitHubSignIn opens GitHub's sign-in page in Aviary's browser, visibly, and returns at once; reads resume in this run once the sign-in lands, and the session state reports progress. Where no window can appear it fails at once with what to do instead.
func (*Manager) HoldNewJobs ¶
HoldNewJobs stops (true) or allows (false) dispatching new jobs. While held, the engine's polls start nothing and leave waiting jobs as they are, and no engine starts. Releasing a hold starts the engine again when a checkpoint stopped it, and polls at once for the work the hold kept back.
func (*Manager) Identity ¶
Identity is this server's instance identity, as signed into its GitHub comments.
func (*Manager) ImportBrowserProfile ¶
ImportBrowserProfile copies the GitHub sign-in from an Aviary browser profile signed in elsewhere into the profile browser delivery reads with, for machines where no sign-in window can appear. A running browser is restarted so its next read is signed in.
func (*Manager) InFlightJobs ¶
InFlightJobs lists the issue numbers of target's jobs that still hold work, which removing the project stops: the engine restarts without target, so its running jobs are checkpointed and none of them resume.
func (*Manager) IssueComment ¶
func (m *Manager) IssueComment(ctx context.Context, repository string, number int, text string, attachments []string) (map[string]any, error)
IssueComment is project_issue_comment: post an update that mentions the issue's author and this instance, so the owning job hears it.
func (*Manager) IssueCreate ¶
func (m *Manager) IssueCreate(ctx context.Context, repository, text, model string, attachments []string) (map[string]any, error)
IssueCreate is project_issue_create: file an issue through gh-create with this instance's identity, uploading and embedding attachments.
func (*Manager) JobAction ¶
func (m *Manager) JobAction(ctx context.Context, action, target string, number int) (map[string]any, error)
JobAction is project_job_retry, _pause, _resume and _stop. It refuses what the job's status does not allow. Stop waits for the agent to exit.
func (*Manager) ListJobs ¶
func (m *Manager) ListJobs(targets []string, status string, states []string, query string, offset, limit int) map[string]any
ListJobs is project_job_list: every job, running and errored ones first, filtered by projects, engine status, board states and a search query, and paged. No targets means every project. total counts the jobs that match them all; with a query, unfiltered_total counts those matching all but the query.
func (*Manager) Reconcile ¶
Reconcile applies a newly loaded configuration: the agents, the projects each one owns, the models: section, and the approval: section. A project's jobs run on its owning agent's model and fallbacks.
func (*Manager) Refresh ¶
Refresh is project_refresh: poll GitHub now. Polls cover every project, so target only checks that it is watched.
func (*Manager) RemoveWatch ¶
RemoveWatch stops runtime watches of target. It reports whether one was removed.
func (*Manager) ResumeAfterRestart ¶
func (m *Manager) ResumeAfterRestart(marker saferestart.Marker)
ResumeAfterRestart records the notice each job a safe restart stopped is resumed with. The engine resumes those jobs in their own sessions from the work state, as after any restart, and prompts each with marker.Message() instead of a bare "continue". Call it before the engine starts.
func (*Manager) RunProjectTask ¶
RunProjectTask runs one fire of a core "project" task as a job on the board of run.Project, which must be a watched project, and waits for its agent to exit. It is the scheduler.ProjectRunner core's scheduler hands project tasks to: the schedule itself lives in core, and Code Loop only runs the job.
func (*Manager) RunningJobs ¶
func (m *Manager) RunningJobs() []saferestart.Job
RunningJobs lists the Code Loop jobs whose agents are running, for a safe restart. Waiting and paused jobs are left out: a restart leaves them alone.
func (*Manager) ScheduledRetry ¶
ScheduledRetry returns the core task a board Retry on the job fires again when the job is a scheduled run, after checking the job can be retried. It returns "" for any other job, which JobAction retries itself.
func (*Manager) SetAviaryAgentRunner ¶
func (m *Manager) SetAviaryAgentRunner(run AviaryAgentRunner)
SetAviaryAgentRunner makes engines started from now on run in-process agent definitions through run. Without one such an agent cannot be dispatched.
func (*Manager) SetBrowser ¶
func (m *Manager) SetBrowser(cfg config.BrowserConfig)
SetBrowser records Aviary's browser settings, which browser delivery reads GitHub through. It takes effect on the next Reconcile.
func (*Manager) SetEngineEnabled ¶
SetEngineEnabled turns starting the engine on or off. With it off the manager still tracks projects and settings, which lets callers exercise the API without reaching GitHub. It is on by default.
func (*Manager) SetLogSource ¶
SetLogSource sets where project_status reads Code Loop log lines from. Without one it reports none.
func (*Manager) SetMentionRouter ¶
func (m *Manager) SetMentionRouter(route MentionRouter)
SetMentionRouter makes engines started from now on send direct mentions on finished or paused jobs to the Code Loop agent through route, which must not block on the agent's answer.
func (*Manager) SetReportDelivery ¶
func (m *Manager) SetReportDelivery(deliver ReportDelivery)
SetReportDelivery sets how projects that opted in to reports send them through an agent's channels.
func (*Manager) SetUsageRecorder ¶
func (m *Manager) SetUsageRecorder(record UsageRecorder)
SetUsageRecorder makes engines started from now on report each agent run's token use, each job run's wall time, and each issue's merged or failed outcome to record, so Code Loop jobs count toward core usage tracking.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown checkpoints every running job, committing and pushing its work, then stops the engine and every subprocess it started. It is safe to call more than once.
func (*Manager) Status ¶
Status is project_status: identity, targets with issue counts, job counts, the jobs in each board state, delivery and the last check, quota per CLI, each CLI provider once with its models and quota, and recent log lines. Passing logOffset returns only the lines logged since that offset. Passing targets counts board states over only their jobs, as project_job_list does.
func (*Manager) Transcript ¶
func (m *Manager) Transcript(target string, number int) []transcript.Event
Transcript returns a job's transcript events, for callers that render them.
type MentionRouter ¶
MentionRouter sends a prompt to the built-in Code Loop agent.
type MentionSource ¶
type MentionSource interface {
// RecentComments lists the comments posted or edited on any issue or
// pull request in repo since the given time, oldest first.
RecentComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
// ClosingIssues names the issues pull request repo#number closes, so a
// mention posted on a pull request reaches the issue it fixes. A number
// that is not a pull request closes nothing.
ClosingIssues(ctx context.Context, repo string, number int) ([]int, error)
}
MentionSource is what the poll modes scan for direct @/aviary:ID mentions. They receive no issue_comment webhook deliveries, so without it a mention posted on an issue or its pull request is never seen.
type OriginatingWorkState ¶
type OriginatingWorkState = core.OriginatingWorkState
OriginatingWorkState is the state of an issue and its pull requests.
type ProjectStateSource ¶
type ProjectStateSource = core.ProjectStateSource
ProjectStateSource reads a board's state.
type PullRequestWorkState ¶
type PullRequestWorkState = core.PullRequestWorkState
PullRequestWorkState is the state of one pull request working an issue.
type RecentComment ¶
type RecentComment struct {
ID int64
// Kind says which API ID belongs to. The zero value is a conversation
// comment.
Kind CommentKind
// NodeID is the GraphQL node ID, the only handle a review body can be
// reacted to through.
NodeID string
// Number is the issue or pull request the comment was posted on.
Number int
Body string
Author string
// CreatedAt is when the comment was first posted, which UpdatedAt stops
// saying as soon as it is edited.
CreatedAt time.Time
UpdatedAt time.Time
}
RecentComment is one comment found by a repository-wide scan of recent issue and pull request comments, or of pull request review comments and review bodies.
type ReportDelivery ¶
ReportDelivery sends one report as agent through target, a scheduled-task route such as "channel:Team Slack" or "session:projects".
type ReviewCommentLister ¶
type ReviewCommentLister = core.ReviewCommentLister
ReviewCommentLister lists pull request review comments.
type ReviewMentionSource ¶
type ReviewMentionSource interface {
// RecentReviewComments lists the inline review comments and submitted
// review bodies posted or edited on any open pull request in repo since
// the given time, oldest first.
RecentReviewComments(ctx context.Context, repo string, since time.Time) ([]RecentComment, error)
}
ReviewMentionSource is what the poll modes scan for direct mentions posted in pull request reviews. Inline review comments and review bodies are separate GitHub APIs from the conversation RecentComments reads, so without it a mention posted in a review is never seen.
type ReviewReactor ¶
type ReviewReactor = core.ReviewReactor
ReviewReactor reacts to pull request review comments.
type SessionAgentOutputRunner ¶
type SessionAgentOutputRunner interface {
RunSessionWithOutput(context.Context, Issue, AgentSession, func(AgentSession), io.Writer) error
}
SessionAgentOutputRunner runs a coding agent in a resumable session, copying its output.
type SessionAgentRunner ¶
type SessionAgentRunner interface {
RunSession(context.Context, Issue, AgentSession, func(AgentSession)) error
}
SessionAgentRunner runs a coding agent in a session it can resume.
type SettingsSnapshot ¶
type SettingsSnapshot = core.SettingsSnapshot
SettingsSnapshot is the engine's live settings.
type SettingsUpdate ¶
type SettingsUpdate = core.SettingsUpdate
SettingsUpdate and SettingsSnapshot live in package core so the browser dashboard's settings modal can speak them without importing the root package.
type StackSource ¶
type StackSource = core.StackSource
StackSource reports whether a repository allows stacked pull requests.
type StatusCLI ¶
type StatusCLI struct {
Name string `json:"name"`
Models []string `json:"models"`
Quota string `json:"quota"`
}
StatusCLI is one CLI provider in project_status: the models its jobs run on, from the provider/model agent specs, and the provider's own quota. A provider/model pair is a model of its provider, not a second provider.
type TargetAgentIdentifier ¶
TargetAgentIdentifier picks the agent for a new job on one target.
type UIReporter ¶
type UIReporter = core.UIReporter
UIReporter receives the engine's published state and log lines.
type UsageRecorder ¶
type UsageRecorder func(domain.UsageRecord)
UsageRecorder receives the token use of one agent run, or one record of Code Loop work.
type Watch ¶
type Watch struct {
Targets []string `json:"targets"`
// Agent is the Aviary agent the targets run under for the watch. Empty
// keeps a target's owning agent, or models.defaults for a target no agent
// owns.
Agent string `json:"agent,omitempty"`
Settings config.ProjectsConfig `json:"settings,omitzero"`
}
Watch is a set of targets watched for the life of the server without being saved to aviary.yaml, as `aviary watch` starts them. Settings overrides the shared projects settings for the whole engine while the watch runs; only its non-zero fields apply.
type WebhookEvent ¶
type WebhookEvent struct {
Kind string
Action string
Repository string
Ref string
Before string
After string
CommitCount int
IssueNumber int
IssueTitle string
CommentBody string
// CommentAuthor is the GitHub login that posted CommentBody, used to
// gate direct-mention triggers to an allowed set of commenters (issue
// #294).
CommentAuthor string
// CommentID is CommentBody's GitHub comment ID, used to react to the
// comment that carried a direct mention.
CommentID int64
// CommentNodeID is CommentBody's GraphQL node ID. A pull_request_review
// delivery's review body can only be reacted to through it.
CommentNodeID string
// MentionedIssues names same-repository issues referenced by a closed
// issue or pull request. The run loop uses these references to treat the
// resulting refresh as a continuation sweep, so unowned work goes through
// the cooperative handoff instead of looking like a brand-new pickup.
MentionedIssues []int
// OnPullRequest reports that an issue_comment delivery's comment was
// posted on a pull request rather than an issue, and ClosesIssues names
// the issues that pull request's description closes, so a direct mention
// posted there reaches the issue it fixes. Review comment
// and review deliveries are always on a pull request, and IssueNumber
// names it.
OnPullRequest bool
ClosesIssues []int
// DiscussionNumber and DiscussionTitle carry the thread a `discussion`
// delivery names. They are kept separate from the issue fields because a
// discussion and an issue can share a number, and the issue fields key
// the follow-up refresh chain.
DiscussionNumber int
DiscussionTitle string
}
WebhookEvent is one GitHub webhook delivery, reduced to what the engine acts on.
type WebhookHandler ¶
type WebhookHandler struct {
Events chan<- WebhookEvent
Secret string
WebhookPath string
}
WebhookHandler accepts GitHub webhook deliveries, records useful delivery details, and asks the aviary to refresh its issue list. The payload is not used as the source of issue data: the next authenticated GitHub CLI query remains authoritative.
func (WebhookHandler) ServeHTTP ¶
func (h WebhookHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type WorkClosureChecker ¶
type WorkClosureChecker = core.WorkClosureChecker
WorkClosureChecker reads an issue's OriginatingWorkState.
Source Files
¶
- agentoutput.go
- agentversion.go
- api.go
- attachments.go
- aviaryagent.go
- browserdelivery.go
- chatcontext.go
- checkpoint.go
- clonereuse.go
- clones.go
- diskfree_unix.go
- engine.go
- engine_clones.go
- ghpublic.go
- githubsession.go
- handoff.go
- issuecreate.go
- issueupdate.go
- linkedpulls.go
- main.go
- manager.go
- mention.go
- merges.go
- oneshotprompt.go
- projecttask.go
- reports.go
- saferestart.go
- settings.go
- snapshot.go
- statecache.go
- transcripts.go
- tunnel.go
- visionagent.go
- wakeup.go
- watchdog.go
- webhook.go
- webhook_manager.go
Directories
¶
| Path | Synopsis |
|---|---|
|
Package browser drives the headless Chrome that browser mode reads GitHub through.
|
Package browser drives the headless Chrome that browser mode reads GitHub through. |
|
Package core holds the types aviary's halves exchange: the issues and comments a source produces, the state a run reads back from GitHub, and the target syntax that names where either comes from.
|
Package core holds the types aviary's halves exchange: the issues and comments a source produces, the state a run reads back from GitHub, and the target syntax that names where either comes from. |
|
Package ngrok starts and supervises the ngrok tunnel that carries GitHub webhook deliveries to the Code Loop engine.
|
Package ngrok starts and supervises the ngrok tunnel that carries GitHub webhook deliveries to the Code Loop engine. |