client

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: Apache-2.0 Imports: 12 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsConflict added in v0.5.0

func IsConflict(err error) bool

IsConflict reports whether err is the API's 409: what was written changed since it was read.

func IsNotFound

func IsNotFound(err error) bool

IsNotFound reports whether err is the API's 404.

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

func New(base, token string, opts ...Option) (*Client, error)

New returns a client for the server at base, authenticating with an API token (server.auth.tokens in kojo.yaml).

func (*Client) ApplyConfig

func (c *Client) ApplyConfig(ctx context.Context, doc []byte, dryRun bool) (*ApplyAnswer, error)

ApplyConfig loads an export. With dryRun nothing is written.

func (*Client) ApprovePlan added in v0.3.0

func (c *Client) ApprovePlan(ctx context.Context, id string) (*store.Session, error)

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

func (c *Client) Campaign(ctx context.Context, id string) (*store.CampaignView, error)

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) Cancel

func (c *Client) Cancel(ctx context.Context, id string) error

Cancel asks a session to stop.

func (*Client) CancelCampaign added in v0.4.0

func (c *Client) CancelCampaign(ctx context.Context, id string) (*store.Campaign, error)

CancelCampaign cancels a campaign and asks its open sessions to stop.

func (*Client) ConfigObject added in v0.5.0

func (c *Client) ConfigObject(ctx context.Context, scope, object string) (*store.Revision, error)

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

func (c *Client) CreateCampaign(ctx context.Context, in NewCampaign) (*store.Campaign, error)

CreateCampaign creates a pending campaign: nothing runs until it is confirmed with its cost bound.

func (*Client) DeclinePlan added in v0.3.0

func (c *Client) DeclinePlan(ctx context.Context, id string) (*store.Session, error)

DeclinePlan declines the plan a session waits on: it ends without changing anything.

func (*Client) Doctor

func (c *Client) Doctor(ctx context.Context) (json.RawMessage, error)

Doctor runs the server's doctor checks and returns the report as JSON.

func (*Client) Eval

func (c *Client) Eval(ctx context.Context, id string) (*store.EvalRun, error)

Eval returns an eval run.

func (*Client) ExportConfig

func (c *Client) ExportConfig(ctx context.Context) ([]byte, error)

ExportConfig returns the day-2 state as YAML.

func (*Client) Limits added in v0.5.0

func (c *Client) Limits(ctx context.Context) (json.RawMessage, error)

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

func (c *Client) MinEvalPassRate(ctx context.Context) (float64, error)

MinEvalPassRate returns the pass rate the server's activation policy requires of an eval.

func (*Client) MoveToFactory added in v0.5.0

func (c *Client) MoveToFactory(ctx context.Context, repoID string) (*FactoryMoveAnswer, error)

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

func (c *Client) ReportHTML(ctx context.Context, id string) ([]byte, error)

ReportHTML returns a session's report page, as a link would show it.

func (*Client) RetryCampaign added in v0.4.0

func (c *Client) RetryCampaign(ctx context.Context, id string) (*store.Campaign, error)

RetryCampaign runs a campaign's failed repositories again.

func (*Client) RevokeReports added in v0.3.0

func (c *Client) RevokeReports(ctx context.Context, id string) error

RevokeReports ends every link to a session's report made so far.

func (*Client) Run

func (c *Client) Run(ctx context.Context, in NewSession) (*store.Session, error)

Run starts a session.

func (*Client) SendMessage

func (c *Client) SendMessage(ctx context.Context, id, text string) (*store.SessionMessage, error)

SendMessage gives a session at work a message its next model step reads.

func (*Client) Session

func (c *Client) Session(ctx context.Context, id string) (*store.Session, error)

Session returns one session.

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) Skills

func (c *Client) Skills(ctx context.Context, repo string) ([]Skill, map[string]string, error)

Skills lists the skills a repository (or the org, when empty) resolves to.

func (*Client) StartEval

func (c *Client) StartEval(ctx context.Context, skill string) (string, error)

StartEval starts an eval of a skill and returns the run's ID.

func (*Client) StartHistoryEval

func (c *Client) StartHistoryEval(ctx context.Context, in HistoryEval) (string, error)

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

func (c *Client) StartProposal(ctx context.Context, scope, skill string) (*store.Proposal, error)

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.

func (*Client) Steps

func (c *Client) Steps(ctx context.Context, id string) ([]store.Step, error)

Steps returns a session's recorded steps.

func (*Client) Wait

func (c *Client) Wait(ctx context.Context, id string, onStep func(store.Step)) (*store.Session, error)

Wait polls a session until it ends or waits for a human, calling onStep for every new step.

type Error

type Error struct {
	Status  int
	Message string
}

Error is an error answer of the API.

func (*Error) Error

func (e *Error) Error() string

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

func WithSurface(s string) Option

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.

type ReportLink struct {
	Session   string    `json:"session"`
	URL       string    `json:"url"`
	ExpiresAt time.Time `json:"expires_at"`
}

ReportLink is a link to a session's shareable report.

type Skill

type Skill struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Layer       string   `json:"layer"`
	Tier        string   `json:"tier"`
	Tools       []string `json:"tools"`
	Overrides   []string `json:"overrides"`
	Writes      bool     `json:"writes"`
}

Skill is a resolved skill, as listed.

Jump to

Keyboard shortcuts

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