Documentation
¶
Overview ¶
Package core is the factory itself: the orchestrator that delegates to skill subagents, the goal critic that checks their work, the merge policy that decides what happens to a change, and the scheduler.
The core holds every credential and never runs a repository command: all untrusted code runs in a sandbox, reached only through a sandbox.Driver. Pushes, pull requests and comments are made by the core through the forge's API.
Index ¶
- Constants
- Variables
- func AssessRisk(p config.MergePolicy, d *diffInfo, criticPassed bool) *store.Risk
- func Decide(p config.MergePolicy, risk *store.Risk, criticPassed, hasChat bool, ...) decision
- func FactoryObject(scope, object string) (repo string, ok bool)
- func IsGo(text string) bool
- func MessagesClosed(s *store.Session) string
- func PersonKey(ms config.MemorySettings, surface string, a store.Actor) string
- func PublicSession(ses *store.Session) bool
- type BudgetHold
- type CampaignSpec
- type CheckResult
- type Engine
- func (e *Engine) CampaignView(ctx context.Context, id string) (*store.CampaignView, error)
- func (e *Engine) Campaigns(ctx context.Context, f store.CampaignFilter) ([]store.CampaignView, error)
- func (e *Engine) CancelCampaign(ctx context.Context, id string, by store.Actor) (*store.Campaign, error)
- func (e *Engine) CancelledNow(ctx context.Context, id string)
- func (e *Engine) CompareWithInUse(ctx context.Context, scope, name string, files map[string]string) (SkillChange, error)
- func (e *Engine) ConfirmCampaign(ctx context.Context, id string, maxCostUSD float64, by store.Actor) (*store.Campaign, error)
- func (e *Engine) ContinueCampaign(ctx context.Context, id string, maxCostUSD float64, by store.Actor) (*store.Campaign, error)
- func (e *Engine) CreateCampaign(ctx context.Context, spec CampaignSpec, author store.Actor) (*store.Campaign, error)
- func (e *Engine) Credentials() sandbox.CredentialSource
- func (e *Engine) DecidePlan(ctx context.Context, sessionID string, approve bool, who, surface string) error
- func (e *Engine) FactoryFiles(ctx context.Context, repoID string) (*FactoryFiles, error)
- func (e *Engine) FactoryState(ctx context.Context, repoID, object string) (*FactoryState, error)
- func (e *Engine) HandleAlert(ctx context.Context, src alerts.Source, a alerts.Alert, deliveryID string) error
- func (e *Engine) HandleForgeEvent(ctx context.Context, f forge.Forge, ev *forge.Event) error
- func (e *Engine) HandleTicketEvent(ctx context.Context, t tracker.Tracker, ev tracker.Event) error
- func (e *Engine) Holds(ctx context.Context, list []store.Session) (map[string]*Hold, error)
- func (e *Engine) ImproveTick(ctx context.Context, now time.Time) (int, error)
- func (e *Engine) LimitsReport(ctx context.Context) (*LimitsReport, error)
- func (e *Engine) MoveFactory(ctx context.Context, repoID, actor string) (*FactoryMove, error)
- func (e *Engine) OnAction(ctx context.Context, a chat.Action) error
- func (e *Engine) OnMessage(ctx context.Context, m chat.Incoming) error
- func (e *Engine) ProposalApproved(ctx context.Context, id, by string, detail map[string]any) (*store.Proposal, error)
- func (e *Engine) ProposalEdited(ctx context.Context, id, by string, files map[string]string, ...) (*store.Proposal, error)
- func (e *Engine) ProposeFactoryChange(ctx context.Context, p FactoryProposal) (*FactoryResult, error)
- func (e *Engine) RejectProposal(ctx context.Context, id, by, reason string) (*store.Proposal, error)
- func (e *Engine) RetryCampaign(ctx context.Context, id string, by store.Actor) (*store.Campaign, error)
- func (e *Engine) Rounds(ctx context.Context, ses *store.Session) ([]PullRequestRounds, error)
- func (e *Engine) Run(ctx context.Context) error
- func (e *Engine) RunCampaigns(ctx context.Context) error
- func (e *Engine) RunOne(ctx context.Context) (bool, error)
- func (e *Engine) RunReaper(ctx context.Context) error
- func (e *Engine) RunScheduler(ctx context.Context) error
- func (e *Engine) SendMessage(ctx context.Context, sessionID string, m store.SessionMessage) (*store.SessionMessage, error)
- func (e *Engine) StartImprovement(ctx context.Context, scope, skill, surface string, by store.Actor) (*store.Proposal, *store.Session, error)
- func (e *Engine) Submit(ctx context.Context, req store.Request) (*store.Session, error)
- func (e *Engine) Tick(ctx context.Context, now time.Time) (int, error)
- func (e *Engine) Wake()
- type Evaluator
- type FactoryFiles
- type FactoryMove
- type FactoryPending
- type FactoryProposal
- type FactoryResult
- type FactoryState
- type FollowUpRound
- type Hold
- type InstallUsage
- type LimitUsage
- type LimitsReport
- type Metrics
- type PersonUsage
- type PullRequestRounds
- type ReportLinks
- type SkillChange
- type SkillResult
- type SkillUsage
- type TriggerUsage
Constants ¶
const ( DefaultCampaignPilot = 3 DefaultCampaignMaxParallel = 5 MaxCampaignParallel = 50 MaxCampaignRepos = 500 // MaxCampaignTitle is in characters. The title is in every pull // request's description, in the part that is never cut. MaxCampaignTitle = 200 )
Bounds of a campaign.
const ( BranchMergePolicy = "kojo/config-merge-policy-" BranchSchedules = "kojo/config-schedules-" BranchMove = "kojo/config-move-to-repository-" )
The branches kōjō writes .factory/ changes on, each followed by a short random suffix. Nothing else is written: never the default branch.
const ( TriggerSchedule = "schedule" TriggerManual = "manual" )
Triggers of a proposal.
const BaselineAuthor = store.ProposalAuthor + ":baseline"
BaselineAuthor is the author of the copy of the version in use that a proposal is measured against. Such a draft exists only while its eval runs; it is not a proposal and nobody edits or activates it.
const KindPRMerged = "pr_merged"
KindPRMerged is the kind of a request a merged pull request started in another repository (on_merge).
Variables ¶
var ( // ErrFactoryUnparsable is a .factory file that does not parse, on the // default branch or on the pending pull request's branch (422). ErrFactoryUnparsable = errors.New("factory: a .factory file does not parse") // ErrFactoryConflict is a proposal kōjō refuses: a trigger_permission // it cannot carry, a branch that moved twice, a Move with nothing to // move (409). ErrFactoryConflict = errors.New("factory: refused") // is kōjō's own; the forge's is logged. ErrFactoryUnavailable = errors.New("factory: the forge did not answer") )
var ErrRejected = errors.New("request rejected")
ErrRejected is returned by the intake functions for a request kōjō will not act on: a repository that is not enabled, an actor without the permission to trigger work.
Functions ¶
func AssessRisk ¶
func AssessRisk(p config.MergePolicy, d *diffInfo, criticPassed bool) *store.Risk
AssessRisk scores a change with deterministic rules: the paths it touches, its size, whether tests moved with the code, and whether the goal critic accepted it. The score is the highest rule that fired, not a sum, so one serious signal is not diluted by harmless ones.
func Decide ¶
func Decide(p config.MergePolicy, risk *store.Risk, criticPassed, hasChat bool, prot *forge.Protection) decision
Decide applies the merge policy. Draft pull requests are the default, and what every mode falls back to: a result the critic rejected, a missing human gate, or an unprotected branch can only make the outcome more conservative.
func FactoryObject ¶ added in v0.5.0
FactoryObject reports whether object at scope is one a repository can keep in .factory/, and which repository.
func IsGo ¶ added in v0.3.0
IsGo reports whether a message is the command that approves a plan: the word go, alone besides mentions, in any case, with an optional ! or full stop.
func MessagesClosed ¶
MessagesClosed says why a session takes no more messages, or "" when it takes them. A session takes messages while it is queued or running with model steps still ahead of it, was asked for by someone trusted, and is a real session that runs skills.
func PersonKey ¶
PersonKey resolves who an actor is, for per-person memory: the key their personal memories are stored under, on whatever surface they ask from.
An email is the person: chat surfaces and the dashboard supply one they verified themselves, and it is already what roles are granted to. A forge login or a chat user without an email is a person of its own ("github:alice") unless an admin linked the account to an email in the memory settings, in which case it is that person. kōjō never guesses that two accounts are one human: a wrong guess would hand one person's memory to another.
func PublicSession ¶ added in v0.3.0
PublicSession reports, from a stored session's checkpoint, whether everything it read came from repositories anyone could read when it ran. A session without a checkpoint, or that never read its repository, is not known to be public.
Types ¶
type BudgetHold ¶ added in v0.3.0
type BudgetHold struct {
// Scope is install, team, repo, skill or person; Name is the team, the
// repository, the skill or the person. Holds shown to people leave a
// person's name and amounts out (Hold.redacted).
Scope string `json:"scope"`
Name string `json:"name,omitempty"`
// Window is day (the last 24 hours) or month (the calendar month, UTC).
Window string `json:"window"`
SpentUSD float64 `json:"spent_usd"`
LimitUSD float64 `json:"limit_usd"`
}
BudgetHold is a budget that is spent.
func (BudgetHold) String ¶ added in v0.3.0
func (b BudgetHold) String() string
type CampaignSpec ¶ added in v0.4.0
type CampaignSpec struct {
Title string `json:"title"`
Task string `json:"task"`
Skill string `json:"skill,omitempty"`
Inputs map[string]string `json:"inputs,omitempty"`
Repos []string `json:"repos,omitempty"`
Team string `json:"team,omitempty"`
Match string `json:"match,omitempty"`
// MaxParallel and Pilot are DefaultCampaignMaxParallel and
// DefaultCampaignPilot when nil.
MaxParallel *int `json:"max_parallel,omitempty"`
Pilot *int `json:"pilot,omitempty"`
}
CampaignSpec is what a person asks a campaign to do: a task, and the repositories to do it in, chosen by list, team or pattern.
type CheckResult ¶
type CheckResult struct {
Name string `json:"name"`
Passed bool `json:"passed"`
Skipped bool `json:"skipped,omitempty"`
ExitCode int `json:"exit_code"`
// Output is the end of the command's output.
Output string `json:"output,omitempty"`
Seconds float64 `json:"seconds,omitempty"`
// OnBase is set for a check that runs on the code from before the pull
// request (skills.Check.OnBase).
OnBase bool `json:"on_base,omitempty"`
// Unverified is set when such a check had a value but no merge base was
// found: it neither passed nor failed, and the result is published only
// as a draft.
Unverified bool `json:"unverified,omitempty"`
}
CheckResult is the outcome of one deterministic check.
type Engine ¶
type Engine struct {
Store store.Store
Config *config.Manager
Skills *skills.Resolver
Models models.Gateway
Driver sandbox.Driver
// Forges and Chats are the configured surfaces, by name.
Forges map[string]forge.Forge
Chats map[string]chat.Adapter
// Trackers are the configured issue trackers, by name (tickets.go).
Trackers map[string]tracker.Tracker
// Fixtures opens an eval fixture's repository by name. Nil outside evals.
Fixtures func(name string) (fs.FS, error)
// FixtureForge opens the forge an eval fixture seeds with issues, pull
// requests and comments, by fixture name, and the repository on it they
// belong to. The forge tools of an eval session read it. Nil outside
// evals; forge.ErrNotFound for a fixture that seeds none.
FixtureForge func(name string) (forge.Forge, forge.Repo, error)
// Evals measures the proposals kōjō makes for its own skills. Without
// one a proposal is left for review unmeasured.
Evals Evaluator
// Reports makes links to shareable session reports for pull request
// descriptions. Without it they link the dashboard only.
Reports ReportLinks
// DefaultImage is the sandbox image of kits that name none.
DefaultImage string
// SandboxTTL bounds a sandbox's life.
SandboxTTL time.Duration
// PublicURL is the dashboard's address, for links in comments.
PublicURL string
// Workers is how many sessions run at once.
Workers int
// KeepSandboxes leaves sandboxes running after a session, for debugging.
KeepSandboxes bool
// Reap removes sandboxes whose TTL has passed, when the driver can.
Reap func(ctx context.Context) error
Log *slog.Logger
Metrics *Metrics
// contains filtered or unexported fields
}
Engine runs sessions.
func (*Engine) CampaignView ¶ added in v0.4.0
CampaignView reads a campaign and where each of its repositories stands.
func (*Engine) Campaigns ¶ added in v0.4.0
func (e *Engine) Campaigns(ctx context.Context, f store.CampaignFilter) ([]store.CampaignView, error)
Campaigns lists campaigns with their totals but no rows: how many of their repositories are over, and what they spent.
func (*Engine) CancelCampaign ¶ added in v0.4.0
func (e *Engine) CancelCampaign(ctx context.Context, id string, by store.Actor) (*store.Campaign, error)
CancelCampaign stops a campaign: nothing more starts, the repositories not started are cancelled, and every open session of the campaign is asked to stop. A session that could not be asked does not stop the others: the errors are returned together, and cancelling the cancelled campaign again asks its open sessions once more.
func (*Engine) CancelledNow ¶
CancelledNow closes the messages of a session a cancel request ended at once (one that was queued or waiting): no worker will. A session still running is left to its worker.
func (*Engine) CompareWithInUse ¶
func (e *Engine) CompareWithInUse(ctx context.Context, scope, name string, files map[string]string) (SkillChange, error)
CompareWithInUse compares skill files with the version of the skill a scope uses now. The dashboard calls it for a proposal's draft, so what the approver is told a proposal loosens, and the refusal of one that widens the skill, are about the draft as it is and the skill as it is.
func (*Engine) ConfirmCampaign ¶ added in v0.4.0
func (e *Engine) ConfirmCampaign(ctx context.Context, id string, maxCostUSD float64, by store.Actor) (*store.Campaign, error)
ConfirmCampaign starts a pending campaign. maxCostUSD is the bound the person confirming saw: it must cover the estimate as it is now, which is worked out again (the budget may have changed since).
func (*Engine) ContinueCampaign ¶ added in v0.4.0
func (e *Engine) ContinueCampaign(ctx context.Context, id string, maxCostUSD float64, by store.Actor) (*store.Campaign, error)
ContinueCampaign starts a paused campaign again. After its pilot that marks the pilot passed. After it spent what was confirmed, maxCostUSD must raise the bound by enough for one more session; it may raise the bound after a pilot too. 0 keeps the bound. While settings/models does not bound what a session costs, no campaign continues.
func (*Engine) CreateCampaign ¶ added in v0.4.0
func (e *Engine) CreateCampaign(ctx context.Context, spec CampaignSpec, author store.Actor) (*store.Campaign, error)
CreateCampaign resolves a campaign's repositories, bounds what it can cost, and stores it pending: nothing runs until a person confirms the bound (ConfirmCampaign). Errors that wrap ErrRejected are the caller's.
func (*Engine) Credentials ¶
func (e *Engine) Credentials() sandbox.CredentialSource
Credentials returns the engine as the sandbox drivers' credential source. A credential named after a forge resolves to clone credentials for the session's own repository, or for one of its reference or linked repositories while the core clones that one (credentialRepo). The proxy only sets them on requests that cannot write (HostCredential.ReadOnly). On GitHub they are also short-lived and scoped to that repository; on GitLab and Forgejo they are the configured token. Nothing else resolves, so a kit cannot name its way to another secret.
func (*Engine) DecidePlan ¶ added in v0.3.0
func (e *Engine) DecidePlan(ctx context.Context, sessionID string, approve bool, who, surface string) error
DecidePlan approves or declines the plan a session waits on, for an operator of the dashboard, the API, MCP or the CLI. It returns ErrRejected (wrapped) when the session waits on no plan or the plan was decided or closed already, and store.ErrNotFound for an unknown session.
func (*Engine) FactoryFiles ¶ added in v0.5.0
FactoryFiles reads .factory/ of a repository's default branch, and no pull request.
func (*Engine) FactoryState ¶ added in v0.5.0
FactoryState says whether a repository keeps object in .factory/ at its default branch, and which open pull request of kōjō's changes it, with the object that pull request's file makes. The list of pull requests is reused for a minute; a proposal made here updates it at once.
func (*Engine) HandleAlert ¶ added in v0.4.0
func (e *Engine) HandleAlert(ctx context.Context, src alerts.Source, a alerts.Alert, deliveryID string) error
HandleAlert turns a verified alert into work. It returns ErrRejected (wrapped) for an alert kōjō does not act on; that is not a failure of the delivery. Nothing is answered to the source: there is nowhere to.
func (*Engine) HandleForgeEvent ¶
HandleForgeEvent turns a verified webhook event into work. It returns ErrRejected (wrapped) for events kōjō ignores; that is not a failure of the delivery.
Who may trigger what is decided here, before anything is queued: a mention only starts work when its author has the repository's trigger permission, and events nobody asked for (a new issue, a new pull request) only run the skill an operator configured for them, without write access. A failed check on one of kōjō's own pull requests is the exception the repository opts into: it continues that pull request with the trust of whoever asked for it, if they still have it (followup.go).
func (*Engine) HandleTicketEvent ¶ added in v0.3.0
HandleTicketEvent turns a verified tracker event into work. It returns ErrRejected (wrapped) for events kōjō does not act on; that is not a failure of the delivery.
func (*Engine) Holds ¶ added in v0.3.0
Holds says, for each session of list that is held back now, why: by session ID. Sessions that are not held are left out. A person's hold names neither the person nor the numbers.
func (*Engine) ImproveTick ¶
ImproveTick is the periodic check: for every scope where self-improvement is on and every skill it covers, it queues a proposal when the skill has no open one, its cooldown has passed, and enough evidence has gathered since the last proposal. It returns how many it queued. It does nothing when another replica leads.
func (*Engine) LimitsReport ¶ added in v0.3.0
func (e *Engine) LimitsReport(ctx context.Context) (*LimitsReport, error)
LimitsReport reads every limit and what counts against it. It lists the teams that own repositories or have limits; the repositories that are enabled, belong to a team, have limits, or spent or ran something; the skills with limits or spend; and the people with an entry or spend this month, most spent first, at most maxPeopleRows. People are listed for whoever asks: the API hides them from viewers (HidePeople).
func (*Engine) MoveFactory ¶ added in v0.5.0
MoveFactory opens one pull request that writes a repository's merge policy and schedules, as set in kōjō, into .factory/. A file that exists is left alone, except a factory.yaml without a merge_policy key, which gains one.
func (*Engine) OnMessage ¶
OnMessage implements chat.Handler: a DM or a mention becomes a request.
The sender's role in kōjō decides what the request may do: operators and admins may trigger write actions, everyone else gets read-only answers.
func (*Engine) ProposalApproved ¶
func (e *Engine) ProposalApproved(ctx context.Context, id, by string, detail map[string]any) (*store.Proposal, error)
ProposalApproved records that a person made a proposal's draft the skill in use. The dashboard calls it after the activation went through; nothing in the core does.
func (*Engine) ProposalEdited ¶
func (e *Engine) ProposalEdited(ctx context.Context, id, by string, files map[string]string, change SkillChange) (*store.Proposal, error)
ProposalEdited records that a person changed a proposal's draft: who, the files as they are now and what they loosen. What was measured was the earlier content, so the proposal's eval no longer stands: the comparison keeps the version in use's run, and the draft's next eval is the one shown against it.
func (*Engine) ProposeFactoryChange ¶ added in v0.5.0
func (e *Engine) ProposeFactoryChange(ctx context.Context, p FactoryProposal) (*FactoryResult, error)
ProposeFactoryChange is the one path every writer of a repository's merge policy or schedules takes. When the repository keeps the object in .factory/ at its default branch, the edit becomes a commit to kōjō's open pull request for that object, or a new pull request, and no revision is written: the live setting changes when the merge's push runs SyncRepo. Otherwise GitManaged is false and the caller writes a revision.
func (*Engine) RejectProposal ¶
func (e *Engine) RejectProposal(ctx context.Context, id, by, reason string) (*store.Proposal, error)
RejectProposal closes a proposal a person turned down and deletes its draft. The reason is kept on the proposal: the next proposal for the skill is shown it, and the same files are not proposed again.
func (*Engine) RetryCampaign ¶ added in v0.4.0
func (e *Engine) RetryCampaign(ctx context.Context, id string, by store.Actor) (*store.Campaign, error)
RetryCampaign runs again the repositories whose item failed and those whose newest session failed, each as its next attempt. The sessions that ended since the last pass are noted first, as a pass would. A campaign that was done runs again, as does one paused after its pilot (so a failed pilot is tried again before the rest); one paused at its cost bound stays paused until it is continued.
func (*Engine) Rounds ¶
Rounds returns the follow-ups of the pull requests a session is part of: for a follow-up session, the pull request it continued; for any other, each pull request it opened that had a follow-up.
func (*Engine) Run ¶
Run claims and runs sessions until ctx ends, then waits for the sessions in flight to checkpoint.
func (*Engine) RunCampaigns ¶ added in v0.4.0
RunCampaigns moves campaigns on until ctx ends: every open campaign at start and at each tick, and a campaign one of whose sessions ended as soon as the worker that ran it says so (campaignSessionEnded). Every replica runs this loop; the campaign's row lock and each start's dedupe key make that safe.
func (*Engine) RunOne ¶
RunOne claims one session, if there is one, and runs it to its next stop: done, failed, or waiting for a human. It reports whether it ran one.
func (*Engine) RunReaper ¶
RunReaper removes expired sandboxes every few minutes: the safety net for sandboxes whose session died without cleaning up. It does nothing when the driver has no reaper (Engine.Reap is nil).
func (*Engine) RunScheduler ¶
RunScheduler fires schedules until ctx ends. Every replica runs this loop; only the one holding the leader lock fires, so a schedule fires once.
func (*Engine) SendMessage ¶
func (e *Engine) SendMessage(ctx context.Context, sessionID string, m store.SessionMessage) (*store.SessionMessage, error)
SendMessage gives a session a message from the dashboard, the API, MCP or the CLI. Only operators reach it, so the author is trusted. It returns ErrRejected (wrapped) when the session takes no messages or the message is out of bounds, and store.ErrNotFound for an unknown session.
func (*Engine) StartImprovement ¶
func (e *Engine) StartImprovement(ctx context.Context, scope, skill, surface string, by store.Actor) (*store.Proposal, *store.Session, error)
StartImprovement queues the work of proposing a change to one skill of one scope, on behalf of someone who asked for it. It refuses when self-improvement is not turned on for the skill, when the evidence is below the threshold, and when the skill already has an open proposal.
type Evaluator ¶
type Evaluator interface {
// Start begins an eval of a draft of a skill and returns the run's ID
// at once; the run continues in the background.
Start(ctx context.Context, skill, draftID, author string) (string, error)
// HasFixtures reports whether the skill has eval fixtures at all.
HasFixtures(skill string) bool
}
Evaluator runs skill evals. internal/eval implements it.
type FactoryFiles ¶ added in v0.5.0
type FactoryFiles struct {
FactoryYAML bool `json:"factory_yaml"`
MergePolicyKey bool `json:"merge_policy_key"`
SchedulesYAML bool `json:"schedules_yaml"`
// Movable is true when neither file exists, or factory.yaml exists
// without a merge_policy key: what the dashboard offers a move for.
Movable bool `json:"movable"`
}
FactoryFiles is which of the files kōjō's settings can live in a repository's default branch has.
type FactoryMove ¶ added in v0.5.0
type FactoryMove struct {
PullRequest *forge.PullRequest
// Created are the files the pull request creates, or gives their
// merge_policy key: ".factory/factory.yaml", ".factory/schedules.yaml".
Created []string
// LeftAlone are the files that exist and stay as they are.
LeftAlone []string
}
FactoryMove is the pull request MoveFactory opened.
type FactoryPending ¶ added in v0.5.0
type FactoryPending struct {
Number int `json:"number"`
URL string `json:"url"`
// Content is the object the pull request's file makes, normalised as
// SyncRepo would store it, so a second edit builds on the first.
Content json.RawMessage `json:"content,omitempty"`
}
FactoryPending is the open pull request kōjō opened for an object.
type FactoryProposal ¶ added in v0.5.0
type FactoryProposal struct {
Repo, Object string // repository id; config.ObjMergePolicy or config.ObjSchedules
Content json.RawMessage // the new object, as PUT /config/object takes it
Actor, Message string // who asked, and their note
// DryRun checks and builds everything and writes nothing: no commit,
// no pull request, no audit entry, no metric.
DryRun bool
}
FactoryProposal is an edit of a repository's settings/merge_policy or schedules, for ProposeFactoryChange.
type FactoryResult ¶ added in v0.5.0
type FactoryResult struct {
// GitManaged is false when the repository does not keep the object in
// .factory/: the caller writes a revision, as before.
GitManaged bool
// PullRequest is the pull request opened or updated; with DryRun, or
// when Unchanged, the pending one, if any.
PullRequest *forge.PullRequest
// Updated is set when an open pull request got (or with DryRun would
// get) a new commit.
Updated bool
// Unchanged is set when the file already makes this object: nothing
// was pushed.
Unchanged bool
// Notes say what of the proposal was not written, such as
// trigger_permission.
Notes []string
}
FactoryResult is what ProposeFactoryChange did.
type FactoryState ¶ added in v0.5.0
type FactoryState struct {
GitManaged bool
// File is the object the default branch's file makes, normalised as
// SyncRepo would store it: what an edit is made against when the scope
// has no revision yet.
File json.RawMessage
Pending *FactoryPending
}
FactoryState says whether a repository keeps an object in .factory/ and which pull request of kōjō's changes it.
type FollowUpRound ¶
type FollowUpRound struct {
Round int `json:"round"`
SessionID string `json:"session_id"`
Trigger string `json:"trigger"`
Check string `json:"check,omitempty"`
Actor string `json:"actor,omitempty"`
Status store.SessionStatus `json:"status"`
Outcome string `json:"outcome,omitempty"`
Commit string `json:"commit,omitempty"`
CreatedAt time.Time `json:"created_at"`
}
FollowUpRound is one follow-up session of one of kōjō's pull requests.
type Hold ¶ added in v0.3.0
type Hold struct {
Reason string `json:"reason"`
Cap *store.CapHold `json:"cap,omitempty"`
Budget *BudgetHold `json:"budget,omitempty"`
}
Hold says why a session does not start: a cap on running sessions (Cap), or a spent budget (Budget). Reason says it in words; for a person's limit it names neither the person nor the numbers.
type InstallUsage ¶ added in v0.3.0
type InstallUsage struct {
PerSessionUSD float64 `json:"per_session_usd,omitempty"`
PerDayUSD float64 `json:"per_day_usd,omitempty"`
PerMonthUSD float64 `json:"per_month_usd,omitempty"`
SpentDayUSD float64 `json:"spent_day_usd"`
SpentMonthUSD float64 `json:"spent_month_usd"`
Running int `json:"running"`
Queued int `json:"queued"`
Held int `json:"held"`
}
InstallUsage is the whole install against the budgets of settings/models.
type LimitUsage ¶ added in v0.3.0
type LimitUsage struct {
Name string `json:"name"`
// Team is a repository's team; Repos are a team's repositories.
Team string `json:"team,omitempty"`
Repos []string `json:"repos,omitempty"`
PerDayUSD float64 `json:"per_day_usd,omitempty"`
PerMonthUSD float64 `json:"per_month_usd,omitempty"`
MaxRunning int `json:"max_running,omitempty"`
SpentDayUSD float64 `json:"spent_day_usd"`
SpentMonthUSD float64 `json:"spent_month_usd"`
Running int `json:"running"`
Queued int `json:"queued"`
// Held is how many queued sessions this limit holds back now.
Held int `json:"held"`
}
LimitUsage is one team or repository against its limits. A limit of 0 is no limit.
type LimitsReport ¶ added in v0.3.0
type LimitsReport struct {
At time.Time `json:"at"`
// Workers is how many sessions this replica runs at once. Every replica
// has its own workers.
Workers int `json:"workers"`
Install InstallUsage `json:"install"`
Teams []LimitUsage `json:"teams"`
Repos []LimitUsage `json:"repos"`
Skills []SkillUsage `json:"skills"`
People []PersonUsage `json:"people"`
Triggers []TriggerUsage `json:"triggers"`
// PeopleDefault is people.default, the limits of everyone without an
// entry of their own; nil when there is none.
PeopleDefault *config.Limit `json:"people_default,omitempty"`
// PeopleHidden says People was left out: it names people's spend,
// which only operators and admins see.
PeopleHidden bool `json:"people_hidden,omitempty"`
}
LimitsReport is every limit with what counts against it now: spend over the last 24 hours and this calendar month, running sessions, and the queued sessions it holds back.
func (*LimitsReport) HidePeople ¶ added in v0.5.0
func (r *LimitsReport) HidePeople()
HidePeople leaves people's rows out of the report, for a reader without the operator role.
type Metrics ¶
type Metrics struct {
// contains filtered or unexported fields
}
Metrics are the factory's Prometheus metrics (design §9): sessions by status, critic pass rate and attempts per skill, tokens and cost, sandbox start-up time, pull requests opened and merged, what became of each pull request (the merge rate and the human-edit rate), and lessons learned.
func NewMetrics ¶
func NewMetrics(reg prometheus.Registerer) *Metrics
NewMetrics registers the metrics on reg. A nil reg keeps them unregistered (tests).
type PersonUsage ¶ added in v0.5.0
type PersonUsage struct {
Name string `json:"name"`
Default bool `json:"default,omitempty"`
PerDayUSD float64 `json:"per_day_usd,omitempty"`
PerMonthUSD float64 `json:"per_month_usd,omitempty"`
MaxRunning int `json:"max_running,omitempty"`
SpentDayUSD float64 `json:"spent_day_usd"`
SpentMonthUSD float64 `json:"spent_month_usd"`
Running int `json:"running"`
Queued int `json:"queued"`
Held int `json:"held"`
}
PersonUsage is one person against their limits: their own entry, or people.default (Default).
type PullRequestRounds ¶
type PullRequestRounds struct {
Repo string `json:"repo"`
Number int `json:"number"`
URL string `json:"url,omitempty"`
Branch string `json:"branch,omitempty"`
// OpenedBy is the session that opened the pull request; empty for a
// person's pull request (Foreign), which kōjō did not open.
OpenedBy string `json:"opened_by"`
Foreign bool `json:"foreign,omitempty"`
MaxRounds int `json:"max_rounds"`
Rounds []FollowUpRound `json:"rounds"`
}
PullRequestRounds are the follow-ups of one of kōjō's pull requests.
type ReportLinks ¶ added in v0.3.0
type ReportLinks interface {
// For returns the address of a new link to the session's report, or
// "" when settings/reports or the session do not allow one. public and
// confidential are what the session knows of itself.
For(ctx context.Context, ses *store.Session, public, confidential bool) (string, error)
}
ReportLinks makes links to shareable session reports (internal/report): a read-only, redacted page of a session that anyone with the link can open without a dashboard account. A pull request's description links the report instead of the dashboard's replay when settings/reports allows.
type SkillChange ¶
type SkillChange struct {
// Widens lists every way the proposed version can do more than the one
// in use: a new tool, another kit, a higher model tier. A proposal with
// any of these is refused.
Widens []string `json:"widens"`
// Loosens lists every way the proposed goals are easier to meet. These
// are allowed, and shown to the approver next to the diff.
Loosens []string `json:"loosens"`
}
SkillChange is what a proposed version of a skill changes, as far as the limits on a proposal go. It is found by comparing the two parsed skills, never by asking the model that wrote the proposal.
func CompareSkills ¶
func CompareSkills(cur, next *skills.Skill) SkillChange
CompareSkills reports what next widens and loosens against cur, the version in use.
A proposal may rewrite the instructions, the description, the outputs and the goals. Everything that decides what the skill can reach or spend is fixed: its tools (it may drop some), its kit (image, resources, egress, credentials, Docker, setup commands), its model tier (it may go down), whether it may change the workspace and whether its report is confidential. Files other than SKILL.md and goals.yaml, the kit file among them, may not change at all.
type SkillResult ¶
type SkillResult struct {
Skill string `json:"skill"`
Task string `json:"task,omitempty"`
// Passed is the goal critic's final verdict.
Passed bool `json:"passed"`
Attempts int `json:"attempts"`
// Summary is the subagent's own final report.
Summary string `json:"summary"`
// Failures are the acceptance criteria still unmet after the last
// attempt.
Failures []string `json:"failures,omitempty"`
Checks []CheckResult `json:"checks,omitempty"`
// Unverified are the checks of the last attempt that could not be run
// (an on_base check without a merge base), one line each. A result
// with any is published only as a draft.
Unverified []string `json:"unverified,omitempty"`
// Outputs are the values the subagent recorded with set_output.
Outputs map[string]string `json:"outputs,omitempty"`
// ChangedFiles are the files this run changed.
ChangedFiles []string `json:"changed_files,omitempty"`
Added int `json:"added,omitempty"`
Removed int `json:"removed,omitempty"`
// Stopped says why the run stopped before the goal critic judged it:
// the skill reached its spend limit (settings/limits skills). A
// stopped result never passed.
Stopped string `json:"stopped,omitempty"`
}
SkillResult is the outcome of one delegated skill run, after the goal critic's last verdict.
type SkillUsage ¶ added in v0.5.0
type SkillUsage struct {
Name string `json:"name"`
PerDayUSD float64 `json:"per_day_usd,omitempty"`
PerMonthUSD float64 `json:"per_month_usd,omitempty"`
SpentDayUSD float64 `json:"spent_day_usd"`
SpentMonthUSD float64 `json:"spent_month_usd"`
// Held is how many queued sessions started for the skill its limits
// hold back now.
Held int `json:"held"`
}
SkillUsage is one skill against its spend limits: the cost of the model calls made for it, outside dry runs and self-improvement.
Source Files
¶
- alerts.go
- approval.go
- auto.go
- branchred.go
- campaign_run.go
- campaign_view.go
- campaigns.go
- critic.go
- engine.go
- factoryconfig.go
- factorymove.go
- feedback.go
- finalize.go
- followup.go
- foreign.go
- history.go
- improve.go
- improve_evidence.go
- improve_guard.go
- improve_session.go
- intake.go
- limits.go
- linked.go
- memory.go
- merge.go
- messages.go
- metrics.go
- onbase.go
- orchestrator.go
- plan.go
- provenance.go
- references.go
- report.go
- scheduler.go
- session.go
- subagent.go
- tickets.go
- tools.go
- workspace.go