Documentation
¶
Overview ¶
Package client is the HTTP client of kōjō's API. The CLI's remote commands (kojo run, kojo sessions, kojo eval, kojo config) and the MCP server are built on it.
Index ¶
- func IsConflict(err error) bool
- func IsNotFound(err error) bool
- type ApplyAnswer
- type ApplyResult
- type Client
- func (c *Client) ApplyConfig(ctx context.Context, doc []byte, dryRun bool) (*ApplyAnswer, error)
- func (c *Client) ApprovePlan(ctx context.Context, id string) (*store.Session, error)
- func (c *Client) Call(ctx context.Context, method, path string, query url.Values, body any) ([]byte, error)
- func (c *Client) Campaign(ctx context.Context, id string) (*store.CampaignView, error)
- func (c *Client) Campaigns(ctx context.Context, status string, limit int) ([]store.CampaignView, error)
- func (c *Client) Cancel(ctx context.Context, id string) error
- func (c *Client) CancelCampaign(ctx context.Context, id string) (*store.Campaign, error)
- func (c *Client) ConfigObject(ctx context.Context, scope, object string) (*store.Revision, error)
- func (c *Client) ConfirmCampaign(ctx context.Context, id string, maxCostUSD float64) (*store.Campaign, error)
- func (c *Client) ConfirmHistoryEval(ctx context.Context, id string, maxCostUSD float64) (*store.EvalRun, error)
- func (c *Client) ContinueCampaign(ctx context.Context, id string, maxCostUSD float64) (*store.Campaign, error)
- func (c *Client) CreateCampaign(ctx context.Context, in NewCampaign) (*store.Campaign, error)
- func (c *Client) DeclinePlan(ctx context.Context, id string) (*store.Session, error)
- func (c *Client) Doctor(ctx context.Context) (json.RawMessage, error)
- func (c *Client) Eval(ctx context.Context, id string) (*store.EvalRun, error)
- func (c *Client) ExportConfig(ctx context.Context) ([]byte, error)
- func (c *Client) Limits(ctx context.Context) (json.RawMessage, error)
- func (c *Client) MinEvalPassRate(ctx context.Context) (float64, error)
- func (c *Client) MoveToFactory(ctx context.Context, repoID string) (*FactoryMoveAnswer, error)
- func (c *Client) Proposals(ctx context.Context, scope, skill string, open bool, limit int) ([]store.Proposal, error)
- func (c *Client) PutConfigObject(ctx context.Context, scope, object string, content json.RawMessage, ...) (rev *store.Revision, changed bool, err error)
- func (c *Client) ReportHTML(ctx context.Context, id string) ([]byte, error)
- func (c *Client) RetryCampaign(ctx context.Context, id string) (*store.Campaign, error)
- func (c *Client) RevokeReports(ctx context.Context, id string) error
- func (c *Client) Run(ctx context.Context, in NewSession) (*store.Session, error)
- func (c *Client) SendMessage(ctx context.Context, id, text string) (*store.SessionMessage, error)
- func (c *Client) Session(ctx context.Context, id string) (*store.Session, error)
- func (c *Client) Sessions(ctx context.Context, status, repo string, limit int) ([]store.Session, error)
- func (c *Client) ShareReport(ctx context.Context, id string, ttl time.Duration) (*ReportLink, error)
- func (c *Client) Skills(ctx context.Context, repo string) ([]Skill, map[string]string, error)
- func (c *Client) StartEval(ctx context.Context, skill string) (string, error)
- func (c *Client) StartHistoryEval(ctx context.Context, in HistoryEval) (string, error)
- func (c *Client) StartProposal(ctx context.Context, scope, skill string) (*store.Proposal, error)
- func (c *Client) Steps(ctx context.Context, id string) ([]store.Step, error)
- func (c *Client) Wait(ctx context.Context, id string, onStep func(store.Step)) (*store.Session, error)
- type Error
- type FactoryMoveAnswer
- type HistoryEval
- type NewCampaign
- type NewSession
- type Option
- type ProposalResult
- type ReportLink
- type Skill
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func IsConflict ¶ added in v0.5.0
IsConflict reports whether err is the API's 409: what was written changed since it was read.
Types ¶
type ApplyAnswer ¶ added in v0.5.0
type ApplyAnswer struct {
DryRun bool `json:"dry_run"`
Results []ApplyResult `json:"results"`
PullRequests []ProposalResult `json:"pull_requests"`
}
ApplyAnswer is what an apply did: the revisions, and the pull requests of the objects repositories keep in .factory/.
type ApplyResult ¶
type ApplyResult struct {
Scope string `json:"scope"`
Object string `json:"object"`
Revision string `json:"revision"`
Changed bool `json:"changed"`
}
ApplyResult is what applying one object did.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one kōjō server.
func New ¶
New returns a client for the server at base, authenticating with an API token (server.auth.tokens in kojo.yaml).
func (*Client) ApplyConfig ¶
ApplyConfig loads an export. With dryRun nothing is written.
func (*Client) ApprovePlan ¶ added in v0.3.0
ApprovePlan gives the go-ahead on the plan a session waits on.
func (*Client) Call ¶
func (c *Client) Call(ctx context.Context, method, path string, query url.Values, body any) ([]byte, error)
Call makes one API request and returns the response body as it came. path is relative to /api/v1 and starts with a slash. A []byte body is sent as YAML, anything else as JSON. It is for callers that pass the API through, such as the MCP server; the typed methods below are for everything else.
func (*Client) Campaign ¶ added in v0.4.0
Campaign returns a campaign and where each of its repositories stands.
func (*Client) Campaigns ¶ added in v0.4.0
func (c *Client) Campaigns(ctx context.Context, status string, limit int) ([]store.CampaignView, error)
Campaigns lists campaigns, newest first, with their totals. An empty status lists all.
func (*Client) CancelCampaign ¶ added in v0.4.0
CancelCampaign cancels a campaign and asks its open sessions to stop.
func (*Client) ConfigObject ¶ added in v0.5.0
ConfigObject returns the active revision of a day-2 object of a scope ("org" or "repo:<id>").
func (*Client) ConfirmCampaign ¶ added in v0.4.0
func (c *Client) ConfirmCampaign(ctx context.Context, id string, maxCostUSD float64) (*store.Campaign, error)
ConfirmCampaign starts a pending campaign. maxCostUSD is the bound the caller agreed to.
func (*Client) ConfirmHistoryEval ¶
func (c *Client) ConfirmHistoryEval(ctx context.Context, id string, maxCostUSD float64) (*store.EvalRun, error)
ConfirmHistoryEval starts the model runs of a validated eval from history. maxCostUSD is the bound the caller agreed to.
func (*Client) ContinueCampaign ¶ added in v0.4.0
func (c *Client) ContinueCampaign(ctx context.Context, id string, maxCostUSD float64) (*store.Campaign, error)
ContinueCampaign starts a paused campaign again; maxCostUSD raises its bound (0 keeps it).
func (*Client) CreateCampaign ¶ added in v0.4.0
CreateCampaign creates a pending campaign: nothing runs until it is confirmed with its cost bound.
func (*Client) DeclinePlan ¶ added in v0.3.0
DeclinePlan declines the plan a session waits on: it ends without changing anything.
func (*Client) ExportConfig ¶
ExportConfig returns the day-2 state as YAML.
func (*Client) Limits ¶ added in v0.5.0
Limits returns GET /limits as it came: every limit with what counts against it now (core.LimitsReport; the client stays free of core).
func (*Client) MinEvalPassRate ¶
MinEvalPassRate returns the pass rate the server's activation policy requires of an eval.
func (*Client) MoveToFactory ¶ added in v0.5.0
MoveToFactory opens the pull request that moves a repository's merge policy and schedules into .factory/ (admin).
func (*Client) Proposals ¶
func (c *Client) Proposals(ctx context.Context, scope, skill string, open bool, limit int) ([]store.Proposal, error)
Proposals lists the changes kōjō proposed to its skills, newest first. Empty scope and skill list them all; open lists only those not decided.
func (*Client) PutConfigObject ¶ added in v0.5.0
func (c *Client) PutConfigObject(ctx context.Context, scope, object string, content json.RawMessage, base, message string) (rev *store.Revision, changed bool, err error)
PutConfigObject writes a new revision of a day-2 object. With base (the revision the change was made from), the server refuses the write with 409 when another revision was activated since (IsConflict). changed is false when the content is what is active already.
func (*Client) ReportHTML ¶ added in v0.3.0
ReportHTML returns a session's report page, as a link would show it.
func (*Client) RetryCampaign ¶ added in v0.4.0
RetryCampaign runs a campaign's failed repositories again.
func (*Client) RevokeReports ¶ added in v0.3.0
RevokeReports ends every link to a session's report made so far.
func (*Client) SendMessage ¶
SendMessage gives a session at work a message its next model step reads.
func (*Client) Sessions ¶
func (c *Client) Sessions(ctx context.Context, status, repo string, limit int) ([]store.Session, error)
Sessions lists sessions, newest first.
func (*Client) ShareReport ¶ added in v0.3.0
func (c *Client) ShareReport(ctx context.Context, id string, ttl time.Duration) (*ReportLink, error)
ShareReport makes a link to a session's report. A zero ttl takes the lifetime settings/reports sets.
func (*Client) StartHistoryEval ¶
StartHistoryEval starts mining and validating the cases of an eval from a repository's history and returns the run's ID. No model runs until ConfirmHistoryEval.
func (*Client) StartProposal ¶
StartProposal asks kōjō to propose a change to one skill of a scope (org or repo:<forge/owner/name>) from the evidence it has gathered.
type FactoryMoveAnswer ¶ added in v0.5.0
type FactoryMoveAnswer struct {
PullRequest struct {
Number int `json:"number"`
URL string `json:"url"`
} `json:"pull_request"`
Created []string `json:"created"`
LeftAlone []string `json:"left_alone"`
}
FactoryMoveAnswer is the pull request that moves a repository's settings into .factory/, with the files it creates and the ones it leaves alone.
type HistoryEval ¶
type HistoryEval struct {
Skill string `json:"skill"`
Repo string `json:"repo"`
TestCmd string `json:"test_cmd"`
Limit int `json:"limit"`
// Since is a date (2026-06-01) or an RFC 3339 time; empty is the
// server's default.
Since string `json:"since,omitempty"`
}
HistoryEval asks for an eval of a skill from a repository's history.
type NewCampaign ¶ added in v0.4.0
type NewCampaign struct {
Title string `json:"title,omitempty"`
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 *int `json:"max_parallel,omitempty"`
Pilot *int `json:"pilot,omitempty"`
}
NewCampaign is the body of POST /campaigns: a task and the repositories to run it in, by list, team and pattern together.
type NewSession ¶
type NewSession struct {
Repo string `json:"repo,omitempty"`
Text string `json:"text,omitempty"`
Skill string `json:"skill,omitempty"`
Number int `json:"number,omitempty"`
IsPR bool `json:"is_pr,omitempty"`
DryRun bool `json:"dry_run,omitempty"`
DraftID string `json:"draft_id,omitempty"`
Inputs map[string]string `json:"inputs,omitempty"`
// Plan asks for a plan and a person's go-ahead before code changes.
Plan bool `json:"plan,omitempty"`
}
NewSession is the body of a session request.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithSurface ¶
WithSurface names the surface requests are attributed to: cli or mcp.
func WithTransport ¶
func WithTransport(rt http.RoundTripper) Option
WithTransport replaces the HTTP transport. The MCP endpoint of a running server uses it to call its own API in process.
type ProposalResult ¶ added in v0.5.0
type ProposalResult struct {
Scope string `json:"scope"`
Object string `json:"object"`
Action string `json:"action"`
Number int `json:"number,omitempty"`
URL string `json:"url,omitempty"`
Notes []string `json:"notes,omitempty"`
}
ProposalResult is a pull request an apply opened or updated, for an object a repository keeps in .factory/. Action is opened, updated or unchanged; with a dry run open, update or unchanged, and Number is the pending pull request's, if any.