intake

package
v0.41.2 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: Apache-2.0 Imports: 22 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 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

View Source
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: the plan service is down or over budget.
	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"
	// 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.

View Source
const APIVersion = "plan/v1"

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.

View Source
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

View Source
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)
	// ErrUnavailable is a gateway the broker could not reach, refused or could not authenticate
	// 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.

Functions

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

func Hash(p Plan) string

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 Material

func Material(p Plan) ([]byte, error)

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.

Types

type Alternative

type Alternative struct {
	Repository string `json:"repository"`
	Why        string `json:"why"`
}

Alternative is another candidate that also fits, and why. Display only.

type Answer

type Answer struct {
	Answer string `json:"answer"`
	Why    string `json:"why"`
}

Answer is the recommendation, and why.

type Budget

type Budget struct {
	CeilingUSD float64 `json:"ceilingUSD"`
	Source     string  `json:"source"`
}

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

func NewPublicity(lookup Lookup, ttl time.Duration, now func() time.Time) *CachedPublicity

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

func (c *CachedPublicity) Public(ctx context.Context, repository string) (bool, error)

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
}

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, both from config. It has no methods by design — `Compose` reads it and `Check` refuses a class that is not in the table, and neither asks it anything.

type ComposeIn

type ComposeIn struct {
	Surface    Surface
	Model      string
	Now        time.Time
	Rev        int
	Round      int
	RoundsLeft int
	Classes    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"`
}

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
	// 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 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.

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

func (g Guard) Candidates(ctx context.Context, asked []string) ([]string, *Refusal)

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"`
	// 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"`
}

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

type Lookup func(ctx context.Context, repository string) (bool, error)

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

func (m *Model) Draft(ctx context.Context, req DraftRequest) (Draft, Usage, error)

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

func (m *Model) Generate(ctx context.Context, req GovernedRequest, out any) (Usage, error)

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 Compose

func Compose(d Draft, in ComposeIn) (Plan, error)

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.

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 Revise added in v0.41.1

func Revise(base Plan, baseHash string, candidate Plan, maxRounds int) (Plan, error)

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.

func WithGaps added in v0.41.1

func WithGaps(p Plan, gaps []Gap) Plan

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

func (p Plan) JSON() ([]byte, error)

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"`
	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 Publicity

type Publicity interface {
	Public(ctx context.Context, repository string) (bool, error)
}

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

type Question struct {
	Text        string `json:"text"`
	Recommended Answer `json:"recommended"`
}

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

func Check(p Plan, candidates []string, classes map[string]Class) *Refusal

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

func CheckCarryForward(base, candidate, next Plan) *Refusal

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

func CheckFinal(p Plan, candidates []string, classes map[string]Class) *Refusal

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 ReasonRefusal

func ReasonRefusal(reason string) *Refusal

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

func RefusalOf(err error) (*Refusal, bool)

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.

func (Refusal) Error

func (r Refusal) Error() string

Error is `reason: sentence`, except where the sentence already starts with it — a `sanitize.CheckDraft` message is refused verbatim, and the reader sees it once.

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 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.

const (
	SurfaceSlack   Surface = "slack"
	SurfaceSession Surface = "session"
)

The surfaces the planner answers on.

type Usage

type Usage struct {
	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.

Jump to

Keyboard shortcuts

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