Documentation
¶
Overview ¶
Package source is the SDK of the source kind: a plugin that reports units of work from a service (pull requests, threads) and acts on them.
A source plugin implements Source and the capability interfaces it has (Ingester, Presenter, Publisher, Lander, Briefer, Planner, Tooler, CLIRunner), passes it to New and serves the result with plugin.Serve. The host reaches it through Client, and serves the plugin's calls back through ServeHost, split the same way into Reporter, Ledger, Reader, Gates, Recorder, Wakes and Services.
Every value the host's context carries across the boundary is a field: the call's priority and meter scope travel as Call (WithCall on the host, CallOf in the plugin), the MCP session and turn in ToolCall, the cost cap and meter scope in AskRequest, and the session's draft rules come from Reader.Session.
Time is the host's: a plugin reports temporal [Value]s, which the host resolves with its clock whenever it reads them.
Index ¶
- Constants
- Variables
- func New(s Source) plugin.Impl
- func WithCall(ctx context.Context, c Call) context.Context
- type ActionRequest
- type Anchor
- type AskRequest
- type AskResult
- type Blocked
- type Book
- type Brief
- type BriefInput
- type BriefIntent
- type BriefRevision
- type BriefStaleRequest
- type BriefWritten
- type Briefer
- type CLIRequest
- type CLIRunner
- type Call
- type Capability
- type Card
- type CardSignal
- type Checkout
- type Client
- func (c *Client) Action(ctx context.Context, req ActionRequest) (json.RawMessage, error)
- func (c *Client) ApplyEffect(ctx context.Context, req EffectRequest) error
- func (c *Client) BriefDescribe(ctx context.Context, in BriefInput) (string, error)
- func (c *Client) BriefInput(ctx context.Context, u plugin.Unit) (BriefInput, error)
- func (c *Client) BriefRevision(ctx context.Context, u plugin.Unit) (BriefRevision, error)
- func (c *Client) BriefStale(ctx context.Context, req BriefStaleRequest) (bool, error)
- func (c *Client) BriefWant(ctx context.Context, u plugin.Unit) (bool, error)
- func (c *Client) CallTool(ctx context.Context, tc ToolCall) (ToolResult, error)
- func (c *Client) Capabilities(ctx context.Context) ([]Capability, error)
- func (c *Client) Checkout(ctx context.Context, u plugin.Unit) (Checkout, bool, error)
- func (c *Client) Identity(ctx context.Context) (Identity, error)
- func (c *Client) Ingest(ctx context.Context, req IngestRequest) (IngestResult, error)
- func (c *Client) Landed(ctx context.Context, d Draft) (plugin.Unit, bool, error)
- func (c *Client) Locate(ctx context.Context, dir string) (plugin.Unit, bool, error)
- func (c *Client) Payload(ctx context.Context, req PayloadRequest) (PayloadResult, error)
- func (c *Client) Place(ctx context.Context, d Draft) (string, error)
- func (c *Client) Placement(ctx context.Context, u plugin.Unit, item string) (Placements, error)
- func (c *Client) Plan(ctx context.Context, u plugin.Unit, st RoundState) (Plan, error)
- func (c *Client) Proposals(ctx context.Context, now time.Time) ([]Draft, error)
- func (c *Client) Publish(ctx context.Context, d Draft) (Evidence, error)
- func (c *Client) Resolve(ctx context.Context, address string) (plugin.Unit, bool, error)
- func (c *Client) RunCLI(ctx context.Context, req CLIRequest, stdout, stderr io.Writer) (int, error)
- func (c *Client) Track(ctx context.Context, req TrackRequest) (Tracked, error)
- func (c *Client) Untrack(ctx context.Context, u plugin.Unit) error
- func (c *Client) Validate(ctx context.Context, d Draft) error
- func (c *Client) Verify(ctx context.Context, d Draft, startedAt time.Time) (Evidence, bool, error)
- func (c *Client) View(ctx context.Context, req ViewRequest) (json.RawMessage, error)
- func (c *Client) Where(ctx context.Context, d Draft) (string, error)
- func (c *Client) WriteState(ctx context.Context, w StateWrite) (Evidence, error)
- type Config
- type Draft
- type DraftOrigin
- type EffectRequest
- type Event
- type EventQuery
- type Evidence
- type ExtractionHealth
- type Fact
- type GateRef
- type GateRequest
- type Gates
- type History
- type Host
- type HostServer
- type Human
- type Identity
- type IngestRequest
- type IngestResult
- type Ingester
- type Item
- type ItemEvidence
- type ItemFields
- type ItemOp
- type ItemQuery
- type ItemResult
- type Lander
- type Ledger
- type Link
- type Listing
- type Offer
- type Option
- type PayloadRequest
- type PayloadResult
- type Person
- type Placement
- type Placements
- type Plan
- type Planner
- type Presenter
- type Priority
- type Publisher
- type Reader
- type Recorder
- type Repo
- type Reporter
- type Round
- type RoundState
- type Sample
- type Services
- type Session
- type Signal
- type Situation
- type Snapshot
- type Source
- type StartRequest
- type StateWrite
- type Task
- type TimeUnit
- type ToolCall
- type ToolResult
- type Tooler
- type TrackRequest
- type Tracked
- type Turn
- type TurnRecord
- type TurnRef
- type UnitMove
- type Value
- type ValueKind
- type Verdict
- type ViewRequest
- type Wake
- type Wakes
- type Wording
- type Workspace
- type WorkspaceRef
Constants ¶
const ( ActorPerson = "person" ActorAgent = "agent" )
The actors of an action.
const ( // RouteSession is a round an agent session asked for. RouteSession = "session" // RouteAsked is a round asked for through the daemon's action. RouteAsked = "asked" // RouteLaunch is a launch or a resume the turn service started. RouteLaunch = "launch" )
The routes a turn goes out on, which EffectRequest.Route names.
const Kind plugin.Kind = "source"
Kind is the source kind's name in plugin.toml and go-plugin.
Variables ¶
var ( // ErrNotFound: the source has no such unit, or will not say. ErrNotFound = errors.New("not found") ErrUnavailable = errors.New("source unavailable") // ErrUnsupported: the other side does not implement the call. ErrUnsupported = errors.New("not supported") // ErrUnfit: the agent's answer to an Ask does not fit what was asked. ErrUnfit = errors.New("answer does not fit") // ErrMayHavePosted: a Publish failed after its post may have reached // the source; the host asks a person to confirm before a retry. ErrMayHavePosted = errors.New("may have been posted") // ErrNoAnswer: the call was canceled, timed out, lost its connection or // failed in transport before the other side answered, which may have // acted on it. ErrNoAnswer = errors.New("no answer") )
Functions ¶
func New ¶
New adapts s to the plugin protocol. The plugin's main serves it:
plugin.Serve(map[plugin.Kind]plugin.Impl{source.Kind: source.New(s)})
Every capability interface s does not implement answers ErrUnsupported.
Types ¶
type ActionRequest ¶
type ActionRequest struct {
Unit plugin.Unit
Action string
Input string
Args json.RawMessage
// Actor is who asked for the action: ActorPerson or ActorAgent; ""
// when the host does not say.
Actor string
}
ActionRequest is an action a person runs on a unit.
type Anchor ¶
type Anchor struct {
Unit plugin.Unit `json:"unit,omitzero"`
Ref string `json:"ref,omitempty"`
Permalink string `json:"permalink,omitempty"`
At time.Time `json:"at,omitzero"`
}
Anchor is a point in a unit, such as a message or a review.
type AskRequest ¶
type AskRequest struct {
Prompt string
// Schema is the JSON schema the answer matches; nil asks for text.
Schema json.RawMessage
Tier string
MaxCostUSD float64
MeterScope string
}
AskRequest is a prompt for the host's agent.
type AskResult ¶
type AskResult struct {
Text string
Model string
CostUSD *float64
Duration time.Duration
Tokens int64
}
AskResult is the agent's answer and what it cost; CostUSD is nil when the agent reported none.
type Book ¶
type Book struct {
Unit plugin.Unit
Turns []Turn
Records []TurnRecord
}
Book is a unit's turns and their records.
type BriefInput ¶
type BriefInput struct {
Text string
Bytes int64
Cut bool
Parts json.RawMessage
}
BriefInput is what a brief of a unit reads now.
type BriefIntent ¶
type BriefIntent struct {
ExtraSchema json.RawMessage
FieldVersions map[string]string
Prompt string
FieldsPrompt string
}
BriefIntent is what the brief intent asks of a brief besides the core fields: the flat JSON schema of its extra fields, nil when it declares none, the version of each by name, and its prompts.
type BriefRevision ¶
type BriefRevision struct {
Revision string
Parts json.RawMessage
// Attempt names what an attempt at the unit now is made from, so a
// failure counts against that attempt only.
Attempt string
}
BriefRevision is what a unit is at, read without its input.
type BriefStaleRequest ¶
type BriefStaleRequest struct {
Written BriefWritten
Current BriefRevision
Version string
Now time.Time
}
BriefStaleRequest asks whether a brief is due again.
type BriefWritten ¶
type BriefWritten struct {
At BriefRevision
Version string
Error string
Failures int
AttemptedAt time.Time
// AttemptOf is the Attempt of the last attempt.
AttemptOf string
}
BriefWritten is what a stored brief was made from and how its last attempt went.
type Briefer ¶
type Briefer interface {
BriefInput(ctx context.Context, u plugin.Unit) (BriefInput, error)
BriefRevision(ctx context.Context, u plugin.Unit) (BriefRevision, error)
BriefDescribe(ctx context.Context, in BriefInput) (string, error)
BriefStale(ctx context.Context, req BriefStaleRequest) (bool, error)
BriefWant(ctx context.Context, u plugin.Unit) (bool, error)
}
Briefer is how the host's brief queue reads a unit. BriefWant is a first turn asking for a unit's brief now: true when one is coming, which the plugin writes through Recorder.PutBrief, false when nothing of the unit is left to read.
type CLIRequest ¶
CLIRequest is a command of the manifest the host runs, with the configuration the plugin reads, as the plugin has no broker in CLI mode.
type CLIRunner ¶
type CLIRunner interface {
RunCLI(ctx context.Context, req CLIRequest, stdout, stderr io.Writer) (exit int, err error)
}
CLIRunner runs the commands the manifest declares, which need no daemon. The command writes to stdout and stderr, which stream to the host as it writes them, and returns its exit code; the plugin process never writes its own stdout.
type Call ¶
type Call struct {
Priority Priority
// MeterScope is the full name of the host's meter scope the call runs
// under; the plugin's samples go back to it through [Services.Meter].
MeterScope string
}
Call is what the host's caller carried in its context, which reaches the plugin as fields of every request.
type Capability ¶
type Capability string
Capability names a capability interface a plugin implements.
const ( CapabilityIngester Capability = "ingester" CapabilityPresenter Capability = "presenter" CapabilityPublisher Capability = "publisher" CapabilityLander Capability = "lander" CapabilityBriefer Capability = "briefer" CapabilityPlanner Capability = "planner" CapabilityTooler Capability = "tooler" CapabilityCLIRunner Capability = "cli" )
func Capabilities ¶
func Capabilities(s Source) []Capability
Capabilities are the capabilities s implements.
type Card ¶
type Card struct {
Label string `json:"label,omitempty"`
Title string `json:"title,omitempty"`
State string `json:"state,omitempty"`
Outcome string `json:"outcome,omitempty"`
Signals []CardSignal `json:"signals,omitempty"`
LastHuman *Human `json:"last_human,omitempty"`
Why string `json:"why,omitempty"`
WaitsOn []Person `json:"waits_on,omitempty"`
Since time.Time `json:"since,omitzero"`
Link string `json:"link,omitempty"`
TurnsLink string `json:"turns_link,omitempty"`
StartedByMe bool `json:"started_by_me,omitempty"`
ClosurePosted bool `json:"closure_posted,omitempty"`
Cares bool `json:"cares,omitempty"`
}
Card is what the plugin shows of one unit.
type CardSignal ¶
type CardSignal struct {
Key string `json:"key,omitempty"`
Value string `json:"value,omitempty"`
Tone string `json:"tone,omitempty"`
At time.Time `json:"at,omitzero"`
}
CardSignal is one line of a card: a key, its value and its tone.
type Checkout ¶
type Checkout struct {
// Repo is "owner/name"; Branch "" is the default branch; Head "" unknown.
Repo, Branch, Head string
// Base is the branch the work merges into; Fork says the head lives in
// another repository.
Base string
Fork bool
}
Checkout is the repository a unit's work checks out.
type Client ¶
Client is the host's handle on a source plugin: every capability interface, each call answering ErrUnsupported when the plugin lacks the capability; Capabilities says which it has. Every request carries the Call of its context.
func (*Client) Action ¶
func (c *Client) Action(ctx context.Context, req ActionRequest) (json.RawMessage, error)
func (*Client) ApplyEffect ¶
func (c *Client) ApplyEffect(ctx context.Context, req EffectRequest) error
func (*Client) BriefDescribe ¶
func (*Client) BriefInput ¶
func (*Client) BriefRevision ¶
func (*Client) BriefStale ¶
func (*Client) Capabilities ¶
func (c *Client) Capabilities(ctx context.Context) ([]Capability, error)
Capabilities are the capabilities the plugin implements.
func (*Client) Ingest ¶
func (c *Client) Ingest(ctx context.Context, req IngestRequest) (IngestResult, error)
func (*Client) Payload ¶
func (c *Client) Payload(ctx context.Context, req PayloadRequest) (PayloadResult, error)
func (*Client) View ¶
func (c *Client) View(ctx context.Context, req ViewRequest) (json.RawMessage, error)
func (*Client) WriteState ¶
type Config ¶
type Config struct {
Plugin json.RawMessage
Host json.RawMessage
// BriefIntent is the brief intent of the plugin's units as the loaded
// profile resolves it; nil when they have none.
BriefIntent *BriefIntent
}
Config is the configuration a plugin reads: its [plugins.<id>] table, and the host keys its manifest's config_reads names.
type Draft ¶
type Draft struct {
ID int64
Unit plugin.Unit
Items []string
Task string
Kind string
Purpose string
Delivery string
Effects []string
// Target is the plugin's target grammar; "" is the unit itself.
Target string
Text string
Reaction string
Replaced string
Origin DraftOrigin
State string
Evidence Evidence
}
Draft is a post the loop proposes or sent; ID is zero for one not stored.
type DraftOrigin ¶
type DraftOrigin struct {
Kind string
TurnSeq int64
Intent string
Workflow string
Rule string
Key string
Unit plugin.Unit
}
DraftOrigin is who proposed a draft.
type EffectRequest ¶
type EffectRequest struct {
Effect string
Unit plugin.Unit
Turn *TurnRef
Draft *Draft
// Route is how a turn effect's turn went out: RouteSession, RouteAsked
// or RouteLaunch; "" for a draft effect.
Route string
// Taken says the agent was seen taking the turn.
Taken bool
// Inputs are a turn effect's turn inputs, a JSON object; nil for none.
Inputs json.RawMessage
}
EffectRequest is an effect of the manifest to apply: Turn is set for a turn effect, Draft for a draft effect.
type Event ¶
type Event struct {
Unit plugin.Unit
Kind string
Actor string
At time.Time
Anchor Anchor
Data json.RawMessage
// Key dedupes the event: a second event of a unit with its kind and key
// is not recorded.
Key string
}
Event is an event on a unit, for the timelines of its tasks.
type EventQuery ¶
EventQuery selects events of Units since Since; empty Kinds reads every kind.
type ExtractionHealth ¶
type ExtractionHealth struct {
Pending int `json:"pending,omitempty"`
BudgetHit bool `json:"budget_hit,omitempty"`
// Oldest is the oldest message not yet extracted; zero with none.
Oldest time.Time `json:"oldest,omitzero"`
}
ExtractionHealth says what a unit's extraction has not yet read.
type GateRef ¶
type GateRef struct {
Gate string
Draft int64
// State is the draft's state once the host's approval policy saw it:
// "proposed", "approved", or "discarded" under dry run.
State string
}
GateRef names the gate a draft opened, and the draft.
type GateRequest ¶
GateRequest proposes a draft, from the MCP session with handle Session when one proposes it.
type Gates ¶
type Gates interface {
// OpenGate proposes a draft, which the host's approval policy holds or
// releases; no plugin approves one. With a session, the host sets the
// draft's origin, task and default items from the session's book and
// refuses an effect the session's intent does not allow; without, the
// origin is the plugin's rule, checked against the manifest. The host
// derives the delivery from the draft's kind through the manifest.
OpenGate(ctx context.Context, req GateRequest) (GateRef, error)
// RecordSent records a post a tool made at once as a sent draft. The
// host refuses it for a session that is not live, or for a tool the
// manifest does not mark posts = "now".
RecordSent(ctx context.Context, d Draft, session, tool string) (GateRef, error)
// RehomeDrafts moves every draft of each move's From, open or sent, onto
// its To in one host transaction, and counts them; applying it twice
// changes nothing, so a plugin retries it after a crash.
RehomeDrafts(ctx context.Context, moves []UnitMove) (int, error)
// SetOverride sets the host overrides of u in one transaction, only
// while each of ifMatch holds its value ("" for unset); a set value ""
// clears one. Written is false when ifMatch did not hold.
SetOverride(ctx context.Context, u plugin.Unit, set, ifMatch map[string]string) (written bool, err error)
}
Gates proposes what waits on the user.
type History ¶
type History interface {
Events(ctx context.Context, q EventQuery) ([]Event, error)
}
History reads the events the host keeps: the plugin's own recorded events and the loop's.
type Host ¶
Host is the host's broker as a plugin calls it, and what the host serves through ServeHost. A nil interface in the host's Host answers every call of it with ErrUnsupported.
No broker method takes the host's loop lock: the host may hold it while it calls the plugin, whose call back would then wait forever. A plugin's reads across calls may see different commits; Notify converges them.
type HostServer ¶
type HostServer struct {
// contains filtered or unexported fields
}
HostServer serves a Host to one plugin on the plugin connection's broker.
func ServeHost ¶
func ServeHost(c *plugin.Client, h Host) (*HostServer, error)
ServeHost serves h on c's broker until Close. The host passes ID as the HostBroker of the kind's StartRequest.
func (*HostServer) Close ¶
func (s *HostServer) Close()
Close stops serving and waits for the server and the calls it serves to end.
type Human ¶
type Human struct {
Who Person `json:"who,omitzero"`
What string `json:"what,omitempty"`
At time.Time `json:"at,omitzero"`
Link string `json:"link,omitempty"`
}
Human is the last thing a person did on a unit.
type IngestRequest ¶
IngestRequest is one run of a manifest job.
type IngestResult ¶
type IngestResult struct {
Summary, Skipped string
}
IngestResult is a job run's outcome, for the job log.
type Ingester ¶
type Ingester interface {
Ingest(ctx context.Context, req IngestRequest) (IngestResult, error)
// Track reads a unit, returning it as its source names it, and follows
// it when req.Follow is set: the host reads, admits, then follows. A
// read not followed reports no snapshot. ErrNotFound or ErrUnavailable
// say why a read failed when the plugin can tell.
Track(ctx context.Context, req TrackRequest) (Tracked, error)
Untrack(ctx context.Context, u plugin.Unit) error
// Resolve is the unit an address a person gives lands in; false for an
// address that is not the plugin's.
Resolve(ctx context.Context, address string) (plugin.Unit, bool, error)
// Locate is the unit a local checkout's directory holds; false for none.
Locate(ctx context.Context, dir string) (plugin.Unit, bool, error)
}
Ingester reads the source: the host runs the manifest's jobs through Ingest, during which the plugin reports what changed; it tracks and untracks units a person follows, and resolves what a person or a link names.
type Item ¶
type Item struct {
ID string `json:"id,omitempty"`
Unit plugin.Unit `json:"unit,omitzero"`
Kind string `json:"kind,omitempty"`
Summary string `json:"summary,omitempty"`
Context string `json:"context,omitempty"`
Options []Option `json:"options,omitempty"`
Deadline string `json:"deadline,omitempty"`
URLs []string `json:"urls,omitempty"`
Contexts []string `json:"contexts,omitempty"`
// Category is the task category the plugin proposes for a new task,
// such as "inbox" or "ready"; never a state name. Empty is inbox.
Category string `json:"category,omitempty"`
Origin Anchor `json:"origin,omitzero"`
Requester Person `json:"requester,omitzero"`
Assignees []Person `json:"assignees,omitempty"`
AssignedAt Anchor `json:"assigned_at,omitzero"`
Basis string `json:"basis,omitempty"`
WaitingOn []Person `json:"waiting_on,omitempty"`
State string `json:"state,omitempty"`
Resolution string `json:"resolution,omitempty"`
Evidence ItemEvidence `json:"evidence,omitzero"`
Trail []ItemEvidence `json:"trail,omitempty"`
Confidence string `json:"confidence,omitempty"`
Ambiguity string `json:"ambiguity,omitempty"`
Provenance string `json:"provenance,omitempty"`
Confirmed bool `json:"confirmed,omitempty"`
// TaskKey groups items into one task: the item id when empty.
TaskKey string `json:"task_key,omitempty"`
UserAt time.Time `json:"user_at,omitzero"`
CreatedAt time.Time `json:"created_at,omitzero"`
UpdatedAt time.Time `json:"updated_at,omitzero"`
}
Item is a commitment the plugin observed: who asks whom for what.
type ItemEvidence ¶
type ItemEvidence struct {
Kind string `json:"kind,omitempty"`
Anchor Anchor `json:"anchor,omitzero"`
}
ItemEvidence is what moved an item, and where.
type ItemFields ¶
type ItemFields struct {
Kind, Summary, Context, Deadline, Ambiguity *string
Options *[]Option
URLs, Contexts *[]string
Category *string
Requester *Person
WaitingOn *[]Person
Confidence *string
}
ItemFields are the fields an op sets; nil leaves a field unchanged.
type ItemOp ¶
type ItemOp struct {
Op string
Unit plugin.Unit
Item string
Anchor Anchor
Fields *ItemFields
Assignees []Person
Basis string
Resolution string
Evidence *ItemEvidence
To *plugin.Unit
LinkKind string
Reason string
}
ItemOp is one change to the host's items ledger.
type ItemResult ¶
ItemResult is the outcome of one op: the item it touched, or why it was refused.
type Lander ¶
type Lander interface {
Landed(ctx context.Context, d Draft) (plugin.Unit, bool, error)
Checkout(ctx context.Context, u plugin.Unit) (Checkout, bool, error)
WriteState(ctx context.Context, w StateWrite) (Evidence, error)
}
Lander says where the plugin's work lands: the unit a sent draft's post landed in, the repository a unit's work checks out, and a task's move written back to the source.
type Ledger ¶
type Ledger interface {
ApplyItems(ctx context.Context, ops []ItemOp) ([]ItemResult, error)
QueryItems(ctx context.Context, q ItemQuery) ([]Item, error)
}
Ledger is the host's items ledger. ApplyItems returns one result per op, in order.
type Link ¶
type Link struct {
URL string `json:"url,omitempty"`
Kind string `json:"kind,omitempty"`
Item string `json:"item,omitempty"`
Evidence Anchor `json:"evidence,omitzero"`
}
Link is an address a unit's source links to.
type Offer ¶
type Offer struct {
Action string `json:"action,omitempty"`
Args json.RawMessage `json:"args,omitempty"`
}
Offer is an action the plugin offers on a unit.
type Option ¶
type Option struct {
Label string `json:"label,omitempty"`
ArguedBy []Person `json:"argued_by,omitempty"`
}
Option is one of the choices a decision item offers.
type PayloadRequest ¶
type PayloadRequest struct {
Unit plugin.Unit
Intent string
Role string
Trigger string
Inputs json.RawMessage
Guidance string
Local string
Owned bool
Plain bool
// LastVerdict is the head the loop's last record covered; nil none.
LastVerdict *Verdict
// Round is the planned round: "first", "follow-up" or "".
Round string
Agent string
// BriefMissing says why the turn runs without a brief; "" with one.
BriefMissing string
Items []string
Task string
}
PayloadRequest asks for the payload of a turn on a unit.
type PayloadResult ¶
type PayloadResult struct {
Arg string
Wording Wording
Facts []Fact
Data json.RawMessage
Contents string
}
PayloadResult is a turn's payload: the argument its prompt names, how the unit is worded, the facts its instructions read, its data for templates and the contents the prompt carries.
type Person ¶
type Person struct {
Key string `json:"key,omitempty"`
Name string `json:"name,omitempty"`
Aliases []string `json:"aliases,omitempty"`
}
Person is a person or group as a source knows them; Key is "<provider>:<id>", "group:<name>" or "system:<name>".
type Placement ¶
type Placement struct {
Repo, Checkout, Role string
}
Placement is where a unit's work runs.
type Placements ¶
type Placements struct {
Default, Suggested *Placement
}
Placements are where a unit's work runs: the plugin's default, and what its source suggests for an item; each nil when there is none.
type Plan ¶
type Plan struct {
Rounds []Round
}
Plan is a unit's round plan: the rounds it would launch. The workflows' facts and the unit's deadline come from its snapshot.
type Planner ¶
type Planner interface {
Plan(ctx context.Context, u plugin.Unit, st RoundState) (Plan, error)
Payload(ctx context.Context, req PayloadRequest) (PayloadResult, error)
ApplyEffect(ctx context.Context, req EffectRequest) error
Proposals(ctx context.Context, now time.Time) ([]Draft, error)
Placement(ctx context.Context, u plugin.Unit, item string) (Placements, error)
}
Planner plans the automatic rounds on the plugin's units from the host's round state, builds a turn's payload, applies the plugin's effects, proposes drafts of its own rules and places a unit's work.
The host calls Plan when it launches or skips a round; workflow facts come from the snapshot, which the plugin reports again after Notify(rounds).
type Presenter ¶
type Presenter interface {
Action(ctx context.Context, req ActionRequest) (json.RawMessage, error)
View(ctx context.Context, req ViewRequest) (json.RawMessage, error)
Identity(ctx context.Context) (Identity, error)
}
Presenter serves what clients show of the plugin: its actions, its views and who the viewer is in the source.
type Priority ¶
type Priority int32
Priority orders who may spend a rate-limited budget when it runs low.
type Publisher ¶
type Publisher interface {
Validate(ctx context.Context, d Draft) error
Where(ctx context.Context, d Draft) (string, error)
Place(ctx context.Context, d Draft) (string, error)
Publish(ctx context.Context, d Draft) (Evidence, error)
Verify(ctx context.Context, d Draft, startedAt time.Time) (Evidence, bool, error)
}
Publisher posts approved drafts. The host calls Publish once, for a draft being sent, and never retries; Verify says whether a draft found sending after a crash was posted at or after startedAt.
type Reader ¶
type Reader interface {
// Tasks are the tasks linked to units.
Tasks(ctx context.Context, units []plugin.Unit) ([]Task, error)
// Books are the turns and records of units.
Books(ctx context.Context, units []plugin.Unit) ([]Book, error)
RoundState(ctx context.Context, u plugin.Unit) (RoundState, error)
// Workspaces lists the workspaces of repo, "owner/name"; "" every one.
Workspaces(ctx context.Context, repo string) (Listing, error)
// Session is the MCP session with handle: its unit, turn and draft rules.
Session(ctx context.Context, handle string) (Session, error)
}
Reader reads the host state a plugin computes from.
type Recorder ¶
type Recorder interface {
RecordEvents(ctx context.Context, events []Event) error
// SetMarks sets marks of u by name; value "" removes one.
SetMarks(ctx context.Context, u plugin.Unit, marks map[string]string) error
PutBrief(ctx context.Context, b Brief) error
}
Recorder writes host data a plugin produces: events on its units, the marks of its rounds and the briefs of its extraction.
type Repo ¶
type Repo struct {
ID, Remote, Path, DefaultBranch string
}
Repo is a repository a workspace manager knows.
type Reporter ¶
type Reporter interface {
Report(ctx context.Context, snapshots []Snapshot) error
Changed(ctx context.Context, units []plugin.Unit, topics []plugin.Topic) error
}
Reporter takes what a plugin observed. Report replaces each unit's snapshot; Changed tells the host that units changed in ways a snapshot does not carry, for its change log.
type Round ¶
type Round struct {
Name string
Workspace WorkspaceRef
Head string
Reason string
// Observed says the round's cause was already seen.
Observed bool
// TurnFacts are the turn slot's facts of the round's turn.
TurnFacts []Fact
// OnSent and OnSkipped are the marks the host writes when it sends or
// skips the round; "" removes a mark.
OnSent, OnSkipped map[string]string
// NotDue says why the round is not due now; "" is due. A round not due
// is not launched, but skipping it still writes OnSkipped.
NotDue string
}
Round is a round a plan would launch on a unit.
type RoundState ¶
type RoundState struct {
Marks map[string]string
SentAt time.Time
AgentHome string
// Today counts the unit's automatic rounds today, DayTotal every unit's.
Today, DayTotal int
// Paused says the unit's rounds are held, by the user or a pause.
Paused bool
// Overrides are the unit's host overrides, by name.
Overrides map[string]string
// Blocked is set while a round's start is blocked on a question.
Blocked *Blocked
}
RoundState is the host's round bookkeeping of one unit, which a Plan reads.
type Sample ¶
type Sample struct {
Scope string
Resource string
Op string
Spawn bool
Duration time.Duration
Failed bool
Points int64
}
Sample is one metered call the plugin made, under the host's meter scope.
type Services ¶
type Services interface {
// Ask fails with ErrUnfit when the answer does not fit the schema.
Ask(ctx context.Context, req AskRequest) (AskResult, error)
Meter(ctx context.Context, s Sample) error
Config(ctx context.Context) (Config, error)
// Profile reads path in the plugin's profile layer, the user's
// plugins/<id>/ over the plugin's own.
Profile(ctx context.Context, path string) ([]byte, error)
}
Services are the host's services a plugin spends: the agent, the meter, its configuration and its profile layer.
type Session ¶
type Session struct {
Unit plugin.Unit
Turn string
TurnSeq int64
Intent string
Role string
// AllowedEffects are the effects a draft of the session may carry.
AllowedEffects []string
}
Session is an MCP session as the host knows it.
type Signal ¶
type Signal struct {
Name string `json:"name,omitempty"`
On bool `json:"on,omitempty"`
// Since is when it turned on; zero when unknown or off.
Since time.Time `json:"since,omitzero"`
}
Signal is a link signal the manifest declares, on one unit.
type Situation ¶
type Situation struct {
// Kind is one of the manifest's situations.
Kind string `json:"kind,omitempty"`
WaitingOn string `json:"waiting_on,omitempty"`
Since time.Time `json:"since,omitzero"`
Reason string `json:"reason,omitempty"`
// Stalled is an After value: the situation is stalled once it holds.
Stalled Value `json:"stalled,omitzero"`
}
Situation is what a unit waits on, as the plugin derives it from its source alone. The host overlays its own state: a run on the unit, a mute (matched by Kind and WaitingOn) and a pending round.
type Snapshot ¶
type Snapshot struct {
Unit plugin.Unit `json:"unit,omitzero"`
// Rev grows with every change of the unit the plugin reports; the host
// compares it with the rev its facts came from.
Rev uint64 `json:"rev,omitempty"`
At time.Time `json:"at,omitzero"`
// Gone says the unit no longer exists in its source.
Gone bool `json:"gone,omitempty"`
// Data is the unit's data, which its templates and rows read.
Data json.RawMessage `json:"data,omitempty"`
// Situation is what the unit waits on as its source says; nil for none.
Situation *Situation `json:"situation,omitempty"`
Card *Card `json:"card,omitempty"`
Items []Item `json:"items,omitempty"`
Facts []Fact `json:"facts,omitempty"`
Signals []Signal `json:"signals,omitempty"`
// Owes are who the unit waits on.
Owes []Person `json:"owes,omitempty"`
Offers []Offer `json:"offers,omitempty"`
// Extraction is the health of the unit's extraction; nil for a unit
// the plugin extracts nothing from.
Extraction *ExtractionHealth `json:"extraction,omitempty"`
// Contexts and Due are the task fields the plugin writes.
Contexts []string `json:"contexts,omitempty"`
Due time.Time `json:"due,omitzero"`
// Links are the addresses the unit's source links to, which the host
// resolves with every manifest's codec.
Links []Link `json:"links,omitempty"`
// Facets are the unit's values of the manifest's facets, by facet id;
// Views the ids of the manifest's views its row is in.
Facets map[string]string `json:"facets,omitempty"`
Views []string `json:"views,omitempty"`
// FacetValues are the values of the manifest's facets that hold more
// than one, by facet id; the host merges them over Facets.
FacetValues map[string][]string `json:"facet_values,omitempty"`
}
Snapshot is everything a plugin reports of one unit; a later snapshot of the unit replaces it whole. Fields holding JSON hold an object whose shape the plugin and its profile layer own.
type Source ¶
type Source interface {
Health(ctx context.Context) (plugin.Health, error)
Start(ctx context.Context, req StartRequest) error
Stop(ctx context.Context) error
Notify(ctx context.Context, units []plugin.Unit, topics []plugin.Topic) error
}
Source is what every source plugin implements. Start receives the host's broker; the plugin keeps it to report snapshots and call the host.
In CLI mode the host runs the plugin binary for one CLIRunner.RunCLI without calling Start: the plugin has no broker and opens no store, which the daemon's process of the plugin owns.
type StartRequest ¶
type StartRequest struct {
// StateDir is the plugin's own state directory, which only it reads.
StateDir string
// Host is the host's broker. A broker interface the host does not serve
// answers every call with [ErrUnsupported].
Host Host
}
StartRequest is what a source plugin receives when the host starts it.
type StateWrite ¶
StateWrite is a task's move the plugin writes back to its source.
type Task ¶
type Task struct {
ID string
Title string
State string
Category string
Parent string
Props json.RawMessage
Units []plugin.Unit
}
Task is a task the host keeps, as a plugin reads it.
type ToolCall ¶
type ToolCall struct {
Tool string
Args json.RawMessage
Session string
Turn string
}
ToolCall is a call of an MCP tool the manifest declares. Session is the MCP session's handle and Turn the turn it serves; Reader.Session reads the session's unit and draft rules.
type ToolResult ¶
type ToolResult struct {
Answer string
Fields json.RawMessage
IsError bool
}
ToolResult names one of the tool's manifest answers and its fields; the host words it from the layered tools.toml.
type Tooler ¶
type Tooler interface {
CallTool(ctx context.Context, call ToolCall) (ToolResult, error)
}
Tooler serves the MCP tools the manifest declares. A result names one of the tool's manifest answers; the host words it from the layered tools.toml.
type TrackRequest ¶
TrackRequest reads a unit, and follows it when Follow is set.
type Turn ¶
type Turn struct {
Seq int64
ID, Intent, Role, Workflow string
State, Head, Session, Summary, Task string
SentAt, StartedAt, EndedAt time.Time
AnsweredAt, At time.Time
Items []string
}
Turn is one turn on a unit. At is when it reached its state.
type TurnRecord ¶
TurnRecord is a record a turn left; Record is its JSON.
type Value ¶
type Value struct {
Kind ValueKind `json:"kind,omitempty"`
Bool bool `json:"bool,omitempty"`
Int int64 `json:"int,omitempty"`
String string `json:"string,omitempty"`
List []string `json:"list,omitempty"`
Duration time.Duration `json:"duration,omitempty"`
Time time.Time `json:"time,omitzero"`
Threshold time.Duration `json:"threshold,omitempty"`
Unit TimeUnit `json:"unit,omitempty"`
}
Value is a fact's value: a literal, or a temporal value the host resolves with its clock whenever it reads it. Build one with its constructor. A temporal value whose Time is zero resolves to its type's zero (a zero duration, false) and has no deadline.
type ValueKind ¶
type ValueKind int
ValueKind is what a Value holds.
const ( KindNone ValueKind = iota KindBool KindInt KindString KindList KindDuration KindTime // KindSince resolves to the duration from Time to the host's now. KindSince // KindAt resolves to true once the host's now reaches Time, a deadline. KindAt // KindAfter resolves to true once the time from Time to the host's now, // counted in Unit, exceeds Threshold; that instant is a deadline. KindAfter )
type ViewRequest ¶
type ViewRequest struct {
View string
Query json.RawMessage
}
ViewRequest asks for one of the plugin's views.
type Wakes ¶
type Wakes interface {
SetWake(ctx context.Context, w Wake) error
ClearWake(ctx context.Context, u plugin.Unit, task string) error
}
Wakes sets and clears when a task of a unit wakes.
type Wording ¶
type Wording struct {
Noun, This, Ref, Short string
}
Wording is how a turn names its unit; the plugin takes the words from its profile layer.
type Workspace ¶
type Workspace struct {
Manager, ID, Repo, RepoID, Path string
DisplayName, Comment string
Branch, PushBranch, Status string
IsMain, Local bool
AgentStates []string
Units []plugin.Unit
}
Workspace is a workspace the host's managers keep. Local says it is on this host.
type WorkspaceRef ¶
type WorkspaceRef struct {
Manager, ID string
}
WorkspaceRef names a workspace in its manager.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package sourcetest runs source plugins in-process, for tests on either side of the source protocol: Stub is a source that reports a scripted snapshot, and Launch connects any source to a host over a real go-plugin connection inside the test binary.
|
Package sourcetest runs source plugins in-process, for tests on either side of the source protocol: Stub is a source that reports a scripted snapshot, and Launch connects any source to a host over a real go-plugin connection inside the test binary. |