Documentation
¶
Overview ¶
Package intake is the broker's governed planner (v3.x conversational intake): `plan/v1` and the canonical hash over its material set, the candidate and access guards that bound what a plan may name, and the one bounded model call whose strict decode is the only way a model's reply becomes a plan. Nothing here is reachable from a route: the tools that expose it are the broker's.
Index ¶
- Constants
- Variables
- func ClassesFor(offers map[string]map[string]Class, fallback map[string]Class, ...) map[string]Class
- func ClassesFromCatalogue(c catalogue.Catalogue) map[string]Class
- func ComposeTemplate(text, context string, candidates []string, classes map[string]Class) (Plan, *Refusal)
- func Hash(p Plan) string
- func IsProfileRevision(base, candidate Plan) bool
- func Material(p Plan) ([]byte, error)
- func PinRecorded(body, profile string) bool
- func Upgrade(v1 Plan, classes map[string]Class) (Plan, *Refusal)
- type Alternative
- type Answer
- type Budget
- type CachedPublicity
- type Class
- type ComposeIn
- type Draft
- type DraftIssue
- type DraftRequest
- type DraftSuggestion
- type Evidence
- type Gap
- type GovernedRequest
- type Guard
- type Issue
- type Lookup
- type MergeShown
- type Model
- type Plan
- func ApplyFloor(p Plan, request string) Plan
- func Compose(d Draft, in ComposeIn) (Plan, error)
- func MaterialRoles(p Plan, classes map[string]Class) Plan
- func RecordProfiles(p Plan) Plan
- func Resuggest(p Plan, classes map[string]Class) Plan
- func Revise(base Plan, baseHash string, candidate Plan, maxRounds int) (Plan, error)
- func WithGaps(p Plan, gaps []Gap) Plan
- type Planner
- type ProfileRefusal
- type Publicity
- type Question
- type Refusal
- func Check(p Plan, candidates []string, classes map[string]Class) *Refusal
- func CheckCarryForward(base, candidate, next Plan) *Refusal
- func CheckFinal(p Plan, candidates []string, classes map[string]Class) *Refusal
- func CheckNamed(text string, known, candidates []string) ([]string, *Refusal)
- func ReasonRefusal(reason string) *Refusal
- func RefusalOf(err error) (*Refusal, bool)
- type Requester
- type Suggestion
- type Surface
- type Usage
Constants ¶
const ( // ReasonPrivateRepository refused before any model call: the planner's route is public-only. ReasonPrivateRepository = "private_repository_unsupported" // ReasonRepositoryNotAllowed: no repository the allowlist serves and the requester may write in // matched the request. The one sentence never names a repository. ReasonRepositoryNotAllowed = "repository_not_allowed" // ReasonNoWrite: the requester cannot write to the one repository they named. ReasonNoWrite = "no_write" // ReasonInvalidDraft is `sanitize.CheckDraft`'s own message, verbatim. ReasonInvalidDraft = "invalid_draft" // ReasonUnresolvedMarker: a final plan still has a ranked gap or a live clarification marker. ReasonUnresolvedMarker = "unresolved_marker" // ReasonInvalidDecisions: a final issue's Decisions section does not hold the closed grammar. ReasonInvalidDecisions = "invalid_decisions" // ReasonPlannerInvalid: the reply, or the plan, is not the shape the contract asks for. ReasonPlannerInvalid = "planner_invalid" ReasonPlannerUnavailable = "planner_unavailable" // ReasonPlannerTimeout: the one call outlived its deadline. ReasonPlannerTimeout = "planner_timeout" // ReasonPlanChanged: the plan was superseded; the newer one is the one to confirm. ReasonPlanChanged = "plan_changed" // ReasonRepositoryUnverified: GitHub could not say whether the repository is public. ReasonRepositoryUnverified = "repository_unverified" // ReasonRepositoryNotInCandidates: the plan names a repository outside the candidate set. The // outsider is never echoed: naming it back would confirm a repository the requester may not know // exists (CD5, §security). ReasonRepositoryNotInCandidates = "repository_not_in_candidates" // ReasonRepositoryNotServedHere: the request names a repository that is not in the candidate set. // Unlike repository_not_in_candidates it names that repository and the candidates, because the // requester typed the name: the plan is never made for a different one (#469). ReasonRepositoryNotServedHere = "repository_not_served_here" // ReasonInvalidClass: the class is not one this broker's config defines. ReasonInvalidClass = "invalid_class" // ReasonNotLinked: the requester's account is not linked to GitHub, so write access is unknown. ReasonNotLinked = "not_linked" // ReasonDailyPlansReached: the requester has used their day's plans. ReasonDailyPlansReached = "daily_plans_reached" // ReasonPlanTooLarge: a field is longer, or holds more items, than the contract's bound. ReasonPlanTooLarge = "plan_too_large" )
The closed refusal list: the reasons the v3.x conversational intake design names, plus the ones it leaves to the builder, and nothing else. Each is a constant here with one sentence in sentences, so no call site invents vocabulary: a reason a metric labels, an audit line records and a person reads has exactly one spelling.
const ( ProfileUnknown = "profile_unknown" ProfileNotOffered = "profile_not_offered" // intake only NotMaintainer = "not_maintainer" ProfileConflict = "profile_conflict" // triage only ProfileNoTestsPaths = "profile_no_tests_paths" // triage only )
The closed list of profile refusals (P12): why a pinned harness profile was not applied, shared by intake (CheckPin) and triage (ResolvePin), so a metric labels one spelling and a reader gets one sentence. A pin refused at triage is never a task failure: the task runs as if unpinned.
The class refusals (class_no_profiles, class_profile_fixed, profile_not_allowed) and profile_internal went with the workflow's leaving the class (WF4, WF7): every class runs every workflow, and the tester runs public careful tasks only, refusing no pin.
const APIVersion = "plan/v2"
APIVersion is the plan contract's one version. A plan whose apiVersion is any other value is refused whole: a consumer re-validates a plan before anything is filed, and a version it does not know is a plan it cannot re-validate.
const APIVersionV1 = "plan/v1"
APIVersionV1 is the version before the profile: recognised only by Upgrade, which shows the same issues again as plan/v2 with a new hash (P14). Check refuses it, so a v1 plan is never filed.
const MaxWhyRunes = 200
MaxWhyRunes bounds a suggestion's why: one line of untrusted model text.
const ModelClaim = "model_claim"
ModelClaim is the kind of every evidence line the model wrote. The broker reads no repository on the planning path, so none of it is verified, and the kind says so instead of the model's own `path`.
const TemplateLabel = "template draft: the plan service is unavailable"
TemplateLabel is what every surface says about a plan the composer wrote: "template draft: the plan service is unavailable" (CD18, §failures). It lives here so the surfaces that show a degraded plan say it in one spelling, and so the live proof can tell the two apart by reading it.
Variables ¶
var ( // ErrInvalid is a reply, or a request, that is not the shape the contract asks for: // `planner_invalid`. It is never retried — the reply is refused whole, and the field and the // bound are in the error. ErrInvalid = errors.New(ReasonPlannerInvalid) // to: `planner_unavailable`. It is never retried inside this package: one call per attempt. ErrUnavailable = errors.New(ReasonPlannerUnavailable) // ErrTimeout is the one call outliving its deadline: `planner_timeout`. The deadline, not the // client's patience, ends the call. ErrTimeout = errors.New(ReasonPlannerTimeout) )
The sentinels the caller maps to the closed refusal list: each spells its own reason, so a wrapped error already reads as the line a person is shown, and `errors.Is` on it is the whole mapping — ErrInvalid to planner_invalid, ErrTimeout to planner_timeout, ErrUnavailable to planner_unavailable. Everything after the colon is the field and the bound, or why the call failed.
var ProfileRefusals = []string{ProfileUnknown, ProfileNotOffered, NotMaintainer, ProfileConflict, ProfileNoTestsPaths, CatalogueUnavailable}
ProfileRefusals is the closed list, in the spec's order.
Functions ¶
func ClassesFor ¶ added in v0.46.0
func ClassesFor(offers map[string]map[string]Class, fallback map[string]Class, repository string) map[string]Class
ClassesFor is the class table a plan for repository is held to: its catalogue's classes when the broker read them, else the config's table (until stage 5). The key is the lowercase name.
func ClassesFromCatalogue ¶ added in v0.46.0
ClassesFromCatalogue is a repository's offered classes as the planner reads them (P2, G4): each class's ceiling and mode, the repository's approveToMerge, and the offered workflows with their roles, the same for every class since the workflow left the class (WF4). The material roles are the repository's default workflow's template, or none when it sets no template: triage chooses them (G3, P15). Floor is that default.
func ComposeTemplate ¶
func ComposeTemplate(text, context string, candidates []string, classes map[string]Class) (Plan, *Refusal)
ComposeTemplate is the degraded composer (CD18): a plan written by a template instead of a model, off by default and reachable only when `human.intake.plan.fallback: composer` names it (PR 2).
It calls nothing. There is no request, no client, no alias and no key here: one issue, the three sections of the issue template in the template's order, the person's words in "what is wrong" and its context beneath them, and the composer's own defaults where the request said nothing.
The title is `factory: <the request's first line>`: the composer read nothing, so the factory is the only area it can name truly, and borrowing an area from the sentence is the inference this mode does not make. A first line that already reads `docs: …` becomes `factory: docs: …` — still a title the validator holds, and the request keeps its own words. `CheckDraft` stays the judge of the title's shape, so a first line no title can carry is refused in the validator's words (`invalid_draft`), never truncated.
It guesses no repository either: it files in the one candidate the request may use, copied as it was given, or it refuses (`repository_not_allowed`) without naming any of them (CD5, §security). With several candidates there is no deterministic answer to "which one", and a template that picked one would be the guess this mode exists to avoid.
Roles and money are the config's, through the same sum Compose uses (CD17), and the class is the alphabetically first one the table defines — a pick, not an inference, so two processes reading one table write the same plan. Every other refusal is the model path's, with the same reason and the same field-and-bound detail, because the plan is held to the same contract: `planner_invalid` for a request the contract cannot carry, the validator's own `invalid_draft`, and `plan_too_large` for a body longer than 16 KiB — refused whole, never truncated.
The plan carries no alternatives and no question: the composer has nothing to recommend and nothing to ask. `planner.at` is when it composed (display; `Hash` never covers it), and `planner.surface` is the caller's: the signature carries no surface, and labelling a Slack plan as a session's would be the one lie this mode must not tell. Every surface says TemplateLabel beside the plan regardless.
func Hash ¶
Hash is `sha256:<hex>` over Material: the value a workflow carries so that what it files is what the person confirmed. It never reads p.Hash, so a caller's claim cannot agree with itself.
func IsProfileRevision ¶ added in v0.46.0
IsProfileRevision is whether candidate is base with only issues' profiles changed: the edit kind a pin is (P4, P5). Every other material field and every body is base's, byte for byte.
func Material ¶
Material is the canonical JSON the hash covers: CD27's set, in its fixed order, issues in array order, compact, and with `[]` rather than `null` for an empty roles or dependsOn — a list that is absent and a list that is empty are the same promise, so they must be the same bytes.
func PinRecorded ¶ added in v0.46.0
PinRecorded is whether body's last profile record is the Decision that pinned profile: a pinned issue says so in the issue filed (CheckFinal).
func Upgrade ¶ added in v0.46.0
Upgrade is a plan/v1 shown again as plan/v2 (P14, G2): deterministic, with no model call, so neither plan_check's contract nor the requester's daily plans are spent. The issues keep their title, body, class and dependsOn; each gains `profile: ""` (the factory's choice) and, when classes came from the catalogue, the suggestion of the factory's choice with an empty why. The roles and the ceiling are re-derived from classes, as Compose derives them; a channel ceiling the v1 plan was lowered to stays when it is still the lower. The new plan carries its new hash and is shown, never filed: the person confirms that one.
classes is the plan repository's table (ClassesFor). A class it no longer holds is refused `invalid_class`, and a plan that is not plan/v1 is refused `planner_invalid`.
Types ¶
type Alternative ¶
Alternative is another candidate that also fits, and why. Display only.
type Budget ¶
Budget is the ceiling this plan's work is charged against and where the number came from: the class's `taskUSD`, or the channel's lower `maxCostUSD`. The broker writes both (CD17); the display value is dollars, and Material hashes the same amount as an integer.
type CachedPublicity ¶
type CachedPublicity struct {
// contains filtered or unexported fields
}
CachedPublicity is Publicity over Lookup, cached as `repoaccess.Checker` caches a permission: one read per repository per TTL under a mutex, a bounded map whose oldest entry is dropped when it is full, and an error that is never cached — a failure is not an answer, and storing it would let one outage outlive the TTL it was supposed to be shorter than.
func NewPublicity ¶
NewPublicity is a Publicity over lookup, holding an answer for ttl, with now injected so a test can move the clock. All three are required: an unbounded TTL, a nil clock or a nil lookup would each leave the guard unable to answer the one question it exists for.
func (*CachedPublicity) Public ¶
Public is whether GitHub reports repository as public, from the cache when a younger answer is there. The repository is read as GitHub reads it, without regard to case; one that is not `owner/name` is an error and asks nobody. Every error is wrapped, so a caller can log the cause and refuse rather than plan on an assumption.
type Class ¶
type Class struct {
Roles []string
CeilingUSD float64
Source string
// The catalogue's reading of the class (ClassesFromCatalogue), all zero for a config row: its
// description, mode (live, shadow, off or unarmed), floor profile, the offered profiles (floor
// first) with their template roles, and the repository's approveToMerge.
Description string
Mode string
Floor string
Offered []string
ProfileRoles map[string][]string
ApproveToMerge bool
}
Class is one row of the broker's class table: the roles a plan of that class carries and the ceiling its work is charged against, from config or, per repository, from the factory's catalogue. `Compose` reads it and `Check` refuses a class that is not in the table.
type ComposeIn ¶
type ComposeIn struct {
Surface Surface
Model string
// ServedModel is the model the gateway reported answering, recorded in `planner.servedModel`.
ServedModel string
Now time.Time
Rev int
Round int
RoundsLeft int
Classes map[string]Class
// Offers are the classes each candidate's catalogue offers, keyed by lowercase repository
// (ClassesFromCatalogue). A plan for a repository in Offers is held to its classes and carries a
// suggestion; one for a repository the broker read no catalogue for falls back to Classes with
// none (until stage 5).
Offers map[string]map[string]Class
// CeilingUSD and CeilingSource are the channel's ceiling, when the channel has one: `maxCostUSD`
// and the string that says so (`channel:C1.maxCostUSD`). Zero means no channel ceiling.
CeilingUSD float64
CeilingSource string
// Logger receives the one line naming every value the reply named that the config owns. A nil
// logger discards it: the plan is the answer, and the line is the operator's.
Logger *slog.Logger
}
ComposeIn is what a plan takes from outside the reply: the surface and model it was asked on, when, its revision, the config's class table, and — when the broker is answering in a Slack channel — that channel's ceiling (CD17).
type Draft ¶
type Draft struct {
Repository string `json:"repository"`
Evidence []Evidence `json:"evidence"`
Alternatives []Alternative `json:"alternatives"`
Issues []DraftIssue `json:"issues"`
Gaps []Gap `json:"gaps"`
}
Draft is the model's answer, as it arrives and before config has a say: the repository and the evidence behind it, the alternatives, one to three issues, and its ranked clarification gaps.
type DraftIssue ¶
type DraftIssue struct {
Title string `json:"title"`
Body string `json:"body"`
Class string `json:"class"`
DependsOn []int `json:"dependsOn"`
Roles []string `json:"roles"`
BudgetUSD float64 `json:"budgetUSD"`
// Suggestion is the model's profile and why; Compose keeps them only when the class offers the
// profile (O1, P15).
Suggestion *DraftSuggestion `json:"suggestion"`
}
DraftIssue is one issue as the reply composed it. Roles and BudgetUSD exist only so that a reply naming them can be dropped and logged (CD17): Compose never reads them, and no plan can carry a model's idea of who works or what it costs.
type DraftRequest ¶
type DraftRequest struct {
Text string
Context string
Candidates []string
Classes []string
// Offers are the classes each candidate's catalogue offers, keyed by lowercase repository: the
// prompt lists them per candidate with their profiles, in place of Classes for that candidate.
Offers map[string]map[string]Class
// Candidate is the broker-verified revision to re-plan. It is serialized as its own JSON
// envelope, separately from Context's 4 KiB bound; settled text and Decisions are data to preserve.
Candidate *Plan
}
DraftRequest is one governed question: what the person asked, the context they brought (both public text, bounded), the candidate repositories the guard already allowed — the only repositories the reply may name — and the classes the broker's table defines, which are the only ones a reply may carry (CD17). Classes is the config's vocabulary shown to the model, so that a reply names one of them: a model guessing at classes the broker does not serve makes `invalid_class` the default outcome rather than the exception. Empty, the prompt says nothing about classes, which is the shape `Compose` refuses.
type DraftSuggestion ¶ added in v0.46.0
type DraftSuggestion struct {
Profile string `json:"profile"`
Why string `json:"why"`
Merge json.RawMessage `json:"merge"`
}
DraftSuggestion is the model's suggested profile, "" for the factory's choice, and one line of why. Merge exists only so that a reply naming a merge outcome is dropped and logged (P3).
type Evidence ¶
type Evidence struct {
Kind string `json:"kind"`
Text string `json:"text"`
URL string `json:"url,omitempty"`
}
Evidence is one reason the planner chose a repository: a path, a thread, a channel. Text is untrusted and inert; URL is either empty or a link the broker built, never one the model sent. Kind is `model_claim` for everything the model wrote (nothing on this path reads the repository to check it) and `candidate` for the composer's own line.
type Gap ¶ added in v0.41.1
type Gap struct {
ID string `json:"id"`
Section string `json:"section"`
Text string `json:"text"`
Recommended Answer `json:"recommended"`
}
Gap is one ranked clarification. ID names its one [NEEDS CLARIFICATION: …] marker in an issue body; Section is what-is-wrong, what-it-should-be, acceptance-check, or scope.
type GovernedRequest ¶ added in v0.38.0
type GovernedRequest struct {
Text string
Context string
Candidates []string
Classes []string
SystemPrompt string
// contains filtered or unexported fields
}
GovernedRequest is one call on the governed route for any typed output (v4 MR4): what the person asked, their context, the candidate repositories the guard allowed, the classes the config defines, and the system prompt naming the output's one JSON shape. DraftRequest is this with plan/v1's prompt; the coordination planner is this with its own.
type Guard ¶
type Guard struct {
// Allow is the repository allowlist the planner serves (`human.intake.plan.repositories`).
// Membership is the value being true: a key set false is a repository the allowlist does not
// serve, so an operator can switch one off without deleting the key.
Allow map[string]bool
// MayWrite answers whether the effective requester may write repository. It closes over the
// Requester, which is why the guard is not told who is asking: one indirection keeps the
// identity out of every signature below it. A nil MayWrite can verify nothing, so the guard
// plans nothing.
MayWrite func(ctx context.Context, repository string) (bool, error)
// Public answers whether GitHub reports repository as public, read once per repository and
// cached (`CachedPublicity`). A nil Public can verify nothing, so the guard plans nothing.
Public Publicity
}
Guard bounds what a plan may name (CD5, §security). Its two answers fail closed: a repository whose write access or visibility cannot be established is refused rather than planned on.
func (Guard) Candidates ¶
Candidates is the set of repositories one plan may name: the allowlist ∩ what was asked ∩ what the requester may write ∩ what GitHub reports public, lowercased, de-duplicated, at most `maxCandidates`, and in the allowlist's order (sorted: a map has no order, and two processes must agree on one).
It answers in the security order — allowlist, asked, write, public — so that no repository reaches the model before every check it can fail has been run.
An empty asked list narrows nothing: the request named no repository, so the candidate set is the allowlist ∩ write ∩ public that CD5 describes, and the model picks from it with its evidence.
Refusals, and what each one is allowed to say:
- One distinct repository was asked and the allowlist does not serve it: `repository_not_allowed`, whose one sentence lists nothing and names nothing.
- It was asked, and the requester cannot write it: `no_write`.
- It was asked, and GitHub reports it private: `private_repository_unsupported`, with the two ways forward — the requester named it, so refusing it is the whole answer.
- Write access or visibility errored: `repository_unverified`. Never planned on a guess.
With several repositories asked, a candidate that fails the write or public check is dropped silently: naming it back would confirm a repository the requester did not name, and the spec's rule is that such a repository is never named, not even as an alternative. When that leaves nothing, the refusal is `repository_unverified` if any check errored (an outage is the reason, and "not allowed" would send an operator after the wrong problem) and `repository_not_allowed` otherwise.
type Issue ¶
type Issue struct {
Index int `json:"index"`
Title string `json:"title"`
Body string `json:"body"`
// Class is the model's one sourced choice, checked against the config's class table: a class
// the config does not define is refused (`invalid_class`), never guessed (CD17).
Class string `json:"class"`
// Profile is the pinned harness profile, "" for the factory's choice. Accepting a suggestion
// pins nothing (P4): only a revision a person makes writes it.
Profile string `json:"profile"`
// Roles are the class's template, written by the broker from config. A role the model named is
// dropped and logged (CD17).
Roles []string `json:"roles"`
// DependsOn is the indices of the earlier issues this one waits for; `Compose` keeps only the
// values that name an earlier index, so a plan can be ordered but never circular.
DependsOn []int `json:"dependsOn"`
// Suggestion is the planner's suggested profile and the merge outcome the broker computed:
// display, so a person sees it and confirms nothing by it. Nil when the plan was made without
// the factory's catalogue.
Suggestion *Suggestion `json:"suggestion,omitempty"`
}
Issue is one defect's draft, as `sanitize.CheckDraft` holds it, with the class it belongs to and the roles and order the broker derives. It is material in every field.
type Lookup ¶
Lookup reads one repository's visibility from GitHub: true for a repository GitHub reports public, false for one it does not. An error means GitHub could not answer, and the caller fails closed.
type MergeShown ¶ added in v0.46.0
type MergeShown struct {
Outcome string `json:"outcome"`
ApproveToMerge bool `json:"approveToMerge"`
}
MergeShown is how the issue's pull request would merge: outcome `auto`, `shadow`, `approval` or `maintainer`, and the repository's approveToMerge it was computed with.
type Model ¶
type Model struct {
// URL is the gateway's base route (`human.intake.plan.url`); the call is appended to it. A
// package never hard-codes a platform endpoint.
URL string
// APIKeyFile is the file holding the `planner` client's key, read at use so a rotated key is
// picked up without a restart. The key is never in the body and never logged.
APIKeyFile string
// Alias is the one model alias the planner may name: `tier-frontier`.
Alias string
// HC is the audited egress client (`httpx.New`): timeouts, the redirect cap, the metadata
// guard. A nil client makes no call.
HC *http.Client
// Deadline bounds the one call. Zero means the contract's 20 s.
Deadline time.Duration
// ReasoningEffort is the call's `reasoning_effort` (`human.intake.plan.reasoningEffort`); empty
// sends no such field.
ReasoningEffort string
}
Model is the one bounded `chat/completions` call (CD18): the route the broker's config names, the pinned alias, the key read from a file at use, the audited egress client and a deadline. It holds no state — every field is configuration, so two callers share one value.
func (*Model) Draft ¶
Draft is the one call for plan/v1: the governed request, the strict decode, and the three ways it fails. It makes exactly one attempt — no retry, no fallback, no second model — because the daily cap and the per-attempt accounting are the caller's, and a client that retried would spend a budget nobody approved.
func (*Model) Generate ¶ added in v0.38.0
Generate is the governed call itself, for every typed output the route serves (CD18, v4 MR4): the pinned alias, temperature 0, the token and reply bounds, the deadline, the key read at use, one attempt. The answer is decoded strictly into out, unknown fields and trailing content refused, so each caller's own type is its contract; the bounds of its fields are the caller's to hold.
type Plan ¶
type Plan struct {
APIVersion string `json:"apiVersion"`
// Rev counts the plan's revisions in its thread or session. It is display: the hash binds the
// plan, and a second Confirm is idempotent on the thread key, not on a revision number.
Rev int `json:"rev"`
// Round and RoundsLeft are the intake's clarification round and the rounds remaining before its
// cap. Both are display only, and separate from Rev's consumer revision count.
Round int `json:"round"`
RoundsLeft int `json:"roundsLeft"`
Planner Planner `json:"planner"`
// Repository is the one repository the plan files into. It is material: a plan for another
// repository is another plan.
Repository string `json:"repository"`
// RepositoryEvidence is why this repository, in the planner's words. Untrusted text, shown and
// never followed; the URLs are the broker's, never the model's.
RepositoryEvidence []Evidence `json:"repositoryEvidence"`
// Alternatives are the other candidates that also fit, with their one line of evidence. Display
// only: a plan names one repository to file into, and the alternatives are the question's
// context.
Alternatives []Alternative `json:"alternatives"`
Issues []Issue `json:"issues"`
// Budget is the ceiling the broker charges this plan's work against, from config (CD17).
Budget Budget `json:"budget"`
// Gaps are the ranked clarifications left in the issue bodies' markers. They are display only:
// the markers themselves are already in Material.
Gaps []Gap `json:"gaps"`
// Question is the highest-ranked gap, kept for clients that render one question.
Question *Question `json:"question"`
// Hash is the canonical hash the broker computed over Material. It is display in the sense that
// Hash never reads it: a plan arrives with the hash its producer claimed, and the consumer
// recomputes over Material and compares.
Hash string `json:"hash"`
}
Plan is `plan/v1`: bounded by construction, every string data, and the whole of what a person is asked to confirm. Everything outside Material is display: a plan read back from a Slack message's metadata or a tool's result re-validates through Check and Hash, and neither reads a display field.
func ApplyFloor ¶ added in v0.44.0
ApplyFloor is the deterministic gap floor (#456): after the model has answered, the broker reads each issue body itself and adds the ranked gaps the model did not. It calls nothing and the same plan always yields the same result.
An element is missing when:
- "What it should be" names no observable behaviour (no RFC 2119 keyword, no verb of a visible result), or is empty or only a "not stated" placeholder;
- "Acceptance check" is missing, or has neither a code-font command nor a MUST/SHOULD observation;
- request (the person's words and context) names no file, path or component. Only the request counts, never the plan's own citations: the broker reads no repository on this path, so a file the plan cites is the model's claim and the live failure this floor exists for.
An element that already holds a live marker is left alone: the model asked. Each added gap has a marker in the right section (scope before the first heading, the others at the end of their own section, above any Decisions), a conservative recommendation, and a rank after every gap already there. IDs continue after the highest g<n> in any body or gap, so a marker never reuses a number a record already settled. The base plan's hash is recomputed; Gaps stay outside Material.
func Compose ¶
Compose is the strict path from a reply to a plan (CD17, CD27): the reply becomes a plan, or it becomes a refusal — never half of one and never a plan config did not write the roles, the ceiling and the class of.
What config owns, config writes:
- each issue's `class` is the reply's choice, checked against `in.Classes`; a class the table does not define is refused (`invalid_class`), never guessed;
- each issue's `roles` are that class's template, and every role the reply named is dropped;
- the plan's `ceilingUSD` is the **sum** of its issues' class ceilings — two $2.00 issues cost $4.00, because a plan of two issues spends two classes' `taskUSD` — lowered to the channel's when the channel's is lower, and `source` names every class that contributed, or the channel when it won (controller ruling, fix round 1);
- `dependsOn` keeps only the indices of earlier issues, and an entry that names anything else drops the list: a plan is ordered, never circular.
What the broker owns, the broker empties: an `Evidence.URL` the reply sent is dropped, because a link a person clicks is one the broker built from a repository it verified (§security). The text stays — it is what the reply says it read — but its kind becomes `model_claim`: nothing on this path reads the repository, so a `path` the model cites is not a path anyone checked (#456).
The repository is the candidate's spelling: lowercased, because the guard hands candidates over lowercased and a plan's hash must not depend on how the model capitalised a name.
A plan from Compose carries its hash, and holds `Check` — the same re-validation `issue_file` runs.
func MaterialRoles ¶ added in v0.46.0
MaterialRoles writes each issue's material roles from the plan repository's catalogue classes (G3): the pinned profile's template roles, else the floor's (none for a floor without a template). A class from the config table is left as Compose wrote it. The hash is renewed when a role changed.
func RecordProfiles ¶ added in v0.46.0
RecordProfiles writes the factory's choice down on a final plan (P4): an issue left unpinned whose suggestion named a workflow gains `A<n>: workflow: factory's choice; suggested <s>`, so the issue filed carries what was chosen against what was suggested. An issue whose Decisions already hold a profile record gains nothing, so the call is idempotent; the hash is renewed when a record is added.
func Resuggest ¶ added in v0.46.0
Resuggest is p with every issue's suggestion rebuilt from classes, the plan repository's table (ClassesFor): a suggestion read back from a client is the client's, so a consumer never shows, stores or files one the broker did not derive. An offered profile and its why are kept, the roles and the merge outcome recomputed; anything else is the factory's choice, and a class from the config table carries none. The suggestion is display: the hash is unchanged.
func Revise ¶ added in v0.41.1
Revise verifies a harness-edited candidate against the plan the broker last returned. The base hash is checked before candidate content is read. Material may change only by replacing existing clarification markers with non-empty text and adding their same-issue D/A records; all other material and every settled record stays verbatim. New record numbers form one global sequence in issue order, while each body retains only its own ascending subset.
The result recomputes the remaining ranked gaps from the base, advances the round and renews the material hash. When the derived round reaches or passes the cap it also replaces every remaining marker with its recommendation and appends an A record, without making a model call. A base round above the cap is planner_invalid; base drift is plan_changed.
The other edit kind is a profile revision (IsProfileRevision): only issues' profiles changed, on a plan with no gap left. It appends one Decision record per changed issue and keeps the rounds.
func WithGaps ¶ added in v0.41.1
WithGaps sets a plan's ranked display gaps and maps the first to the legacy Question view. The input is cloned so later caller edits cannot mutate a plan that has already been composed.
func (Plan) JSON ¶
JSON is the plan as a reader sees it: compact, the contract's order, and `[]` for the lists a plan always has. A plan without a hash gains the one Hash computes; a plan that arrived with one keeps the value it claims, so a consumer can show what it was given beside what it computed.
type Planner ¶
type Planner struct {
Model string `json:"model"`
// ServedModel is the `model` the gateway's reply named: what actually answered behind the
// alias, so a swap behind `tier-frontier` shows in the plan. Empty when the reply names none
// and for the composer. Display only: `Hash` never reads it.
ServedModel string `json:"servedModel,omitempty"`
Surface string `json:"surface"`
At time.Time `json:"at"`
}
Planner is who composed a plan, on which surface, when. Display: the model and the surface are audited beside the hash, and a person reading a proposal is told what wrote it.
type ProfileRefusal ¶ added in v0.46.0
type ProfileRefusal struct {
Code, Class, Profile string
}
ProfileRefusal is one refused pin with the fields its sentence names. It is kept apart from refuse()'s single-diagnostic rule because these sentences take several fields. Every field is a config name the reader may see in the catalogue: none is a repository.
func CheckPin ¶ added in v0.46.0
func CheckPin(c catalogue.Catalogue, class, profile string) *ProfileRefusal
CheckPin is intake's early check of a pinned workflow (P6), against the plan repository's catalogue, in the order triage checks it (triage.ResolvePin): who pins, the workflow, then whether intake can show the workflow's roles. Nil when the pin holds or there is none. Since the workflow left the class (WF4), every class may run every workflow: the class is only named.
A workflow the catalogue does not list is unknown here: the catalogue lists every workflow a pin could name.
func (ProfileRefusal) Refusal ¶ added in v0.46.0
func (r ProfileRefusal) Refusal() *Refusal
Refusal is r as a plan_check refusal: its code and its one sentence.
func (ProfileRefusal) Sentence ¶ added in v0.46.0
func (r ProfileRefusal) Sentence() string
Sentence is the code's one sentence. The switch is closed: a code outside the list panics, the same programming error refuse() panics on.
type Publicity ¶
Publicity answers the one question the public-only guard asks: does GitHub report this repository as public? The planner reads public text only, and this is the read that decides it — one interface, implemented by GitHub in production and by a double in a test.
type Question ¶
Question is the at most one thing the broker asks before filing, with its recommendation: a question without a recommendation is a question the reader has to answer without the broker's reading of the evidence.
type Refusal ¶
type Refusal struct {
// Reason is one of the closed list's constants: the metric label and the audit field.
Reason string `json:"reason"`
// Sentence is one line for the person: what happened and what they can do.
Sentence string `json:"sentence"`
}
Refusal is why a plan was not made or not filed, whole. It is the answer a caller maps to one line, and it implements error so a tool's writer finds it with errors.As and shows Sentence rather than a failure's text.
func Check ¶
Check holds a plan to the contract's closed rules before anything is filed, in this order: the version, the issue count, the numbering and the dependency order, each draft through `sanitize.CheckDraft`, the repository and every alternative against the candidate set, each class against the config's table, the evidence bounds and the one question. It returns nil when the plan holds. It is the re-validation every consumer runs — `issue_file` and `run_create` alike — so a plan that changed after it was shown is refused here and nowhere else.
The issues' indices are the contract's numbering, not a label a plan carries: they are 1..n in array order, and a dependency names an earlier issue only. `Compose` writes them that way, so the rule is a no-op on a fresh plan and the whole of what a read-back plan can get wrong — a duplicate index filed twice, a gap, a dependency on work a filing pass has not reached.
A repository outside candidates — the plan's own, or one named as an alternative — is refused whole and never named (Review Focus 1): the plan may be guessing at repositories the requester does not know exist, and an alternative is shown to the person as "also fits". Diagnostics name the field and the bound; a draft's message is `CheckDraft`'s own, verbatim.
func CheckCarryForward ¶ added in v0.41.1
CheckCarryForward holds a model re-plan to the edits already verified in candidate. Replacement text from base's resolved markers must still occur verbatim in the same issue, and every D/A record present in candidate must survive unchanged and in order there. The model may rewrite unsettled prose and refine remaining questions; it may not rewrite intake history.
func CheckFinal ¶ added in v0.41.1
CheckFinal is Check plus the external filing rules. Intermediate plans may carry ranked gaps and their body markers; a final plan may carry neither, and every issue's optional Decisions section must hold the shared grammar. The two new refusals use the closed list's fixed sentences rather than echoing draft text.
func CheckNamed ¶ added in v0.44.0
CheckNamed is the deterministic answer to "did the request name a repository?", asked before any model call so the model is never left to pick the only candidate and invent a reason (#469).
A repository counts as named when the text holds, as a whole token and without regard to case:
- `owner/name`, when the owner is one the factory knows or the form is a github.com URL;
- a URL to github.com/owner/name;
- a bare name that is the name part of a repository in known (the allowlist, the asked set and the candidates), so `ai` is not `ai-native-ref` and `runlore-kb` is not `runlore`.
Any named repository outside candidates refuses the request with `repository_not_served_here`, whose sentence names it and the candidates: the requester typed the name and owns the candidate set, so neither is a secret from them. Otherwise the candidates narrow to the ones named, in their order, so a plan can only target a repository the text asked for; with nothing named they are returned unchanged.
func ReasonRefusal ¶
ReasonRefusal is reason's refusal, in the closed list's one sentence: for the reasons a caller decides itself rather than receives from a call — a Slack user the link tables do not know (`not_linked`), a spent daily cap (`daily_plans_reached`), a check that could not be made (`repository_unverified`) — so that no call site writes the sentence a person reads. A reason outside the list, or one whose sentence names a diagnostic, panics as refuse does: this is for the sentences that stand alone.
func RefusalOf ¶
RefusalOf is the closed refusal err spells, when err is one of the model call's sentinels: ErrInvalid is `planner_invalid` with the field and the bound the error names, ErrTimeout is `planner_timeout` and ErrUnavailable is `planner_unavailable`, each in the closed list's sentence rather than the vendor's text. ok is false for an error that is none of the three, and a caller then answers its own rather than passing a transport failure off as a refusal.
type Requester ¶
type Requester struct {
// Key is the requester's stable identity: the daily cap's key and the audit line's field. It is
// the principal's own key, never a display name, so a rename does not reset a cap.
Key string
// Login is the requester's GitHub login, the one `repoaccess` checks write access for. Empty
// means the account is not linked to GitHub, and no write access can be established.
Login string
}
Requester is the effective requester of a plan: who is asking, resolved once by the API and threaded to the guard so that the guard never re-derives it. The spec's rule is that the candidate set is the allowlist ∩ what *this* requester may write, so the identity behind the write check is decided in one place — the request's authentication — and not here.
type Suggestion ¶ added in v0.46.0
type Suggestion struct {
// Profile is an offered profile of the issue's class, "" for the factory's choice.
Profile string `json:"profile"`
// Roles are the suggested profile's template roles, from the catalogue (G3).
Roles []string `json:"roles"`
// Merge is the broker's, from the class's mode and approveToMerge, never the model's (P3).
Merge MergeShown `json:"merge"`
// Why is the model's one line, at most MaxWhyRunes characters; untrusted text.
Why string `json:"why"`
}
Suggestion is what the planner suggests for an issue and what the broker read from the catalogue to show beside it. Display only: the hash never reads it.
type Surface ¶
type Surface string
Surface is where a plan was asked for. It is the metric label and the audit field, so the set is closed: a surface nobody labels is a plan nobody can account for.
type Usage ¶
type Usage struct {
// Model is the `model` the gateway's reply named, empty when it names none.
Model string
PromptTokens int
CompletionTokens int
AttemptID string
ReservationID string
SettlementID string
ReservedMicroUSD int64
SettledMicroUSD int64
}
Usage is what the call cost, from the reply's own `usage`: the broker attributes a spend it can see, and a reply without usage is refused. The planning attempt's reconciliation identifiers and amounts ride along when the governed route supplies them (v4 MR4); today's gateway supplies none, and a broker-side call has no AgentRun id to invent in their place.