thinkingpolicy

package
v0.30.4 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package thinkingpolicy validates the canonical thinking-value contract and the per-backend thinking policy from a portable Umpire schema shared with the TypeScript packages.

The Umpire schema (schemas/thinking_policy.umpire.json) is the single file of truth for both canonical value validity and backend-specific thinking support. It uses:

  • A check rule for canonical value validation (off, minimal, low, medium, high, xhigh, max).
  • Conditions (backend, resume) and an eitherOf group with fairWhen branches that encode which canonical values each backend supports on a fresh start versus an explicit resume.

The generated Check function evaluates both the canonical check and the backend policy branches. The hand-written Evaluate function wraps the generated Check to produce a four-valued Outcome (OK, UnsupportedCapability, UnsupportedValue, StartOnly) by inspecting the generated Fair flag and, when needed, re-evaluating with resume=false to distinguish StartOnly from UnsupportedValue.

The set of backends with thinking support is derived from the schema's eitherOf branches at init time, so adding a new backend with thinking support requires only a schema change — no hand-written policy table updates.

ValidateThinkingForBackendResume is exported as part of the portable contract for callers that need to validate resume-time thinking independently. The current follow-up path does not accept a thinking value (thinking is set at session start), so this function has no production callers yet; it is available for hosts and future wiring.

Index

Constants

View Source
const (
	Empty       thinkingPolicyBranch = iota
	FullSupport thinkingPolicyBranch = iota
	ClaudeStart thinkingPolicyBranch = iota
)

Variables

This section is empty.

Functions

func CanonicalValues

func CanonicalValues() []string

CanonicalValues is the single Go source for the canonical thinking tuple. It is verified against the Umpire schema's canonical condition and the TypeScript THINKING_LEVELS tuple by introspection tests so the three never drift apart.

func IsCanonical

func IsCanonical(value string) bool

IsCanonical reports whether value is empty or one of the canonical values, using the generated Umpire evaluation.

func ResumeValues

func ResumeValues(backend string) []string

ResumeValues returns the thinking values supported by backend on an explicit resume, or nil if the backend is unknown or has no thinking support.

func StartValues

func StartValues(backend string) []string

StartValues returns the thinking values supported by backend when starting, or nil if the backend is unknown or has no thinking support.

func ValidateCanonical

func ValidateCanonical(value string) error

ValidateCanonical returns a descriptive error for a non-canonical value.

Types

type ChallengeResult

type ChallengeResult struct {
	FieldName    string
	Status       FieldStatus
	Explanations []string
}

ChallengeResult holds the result of a Challenge call.

type FieldStatus

type FieldStatus struct {
	Enabled   bool
	Required  bool
	Satisfied bool
	Fair      bool
	Reason    *string  // nil when enabled; first blocking reason otherwise
	Reasons   []string // all blocking reasons; empty slice when enabled
	Valid     *bool    // nil = no validator; non-nil = validation result
	Error     string   // non-empty only when Valid != nil && !*Valid
}

FieldStatus mirrors the conformance expectedAvailability shape exactly. Valid and Error are only populated when a named validator is attached to the field and the field is currently enabled and satisfied.

type Outcome

type Outcome int

Outcome distinguishes the static thinking policy result for a given (backend, value, resume) combination so callers can surface a specific error.

const (
	// OK means the combination is accepted.
	OK Outcome = iota
	// UnsupportedCapability means the backend does not support thinking at all.
	UnsupportedCapability
	// UnsupportedValue means the backend supports thinking but not this value.
	UnsupportedValue
	// StartOnly means the value is only supported when starting a session, not
	// on an explicit resume.
	StartOnly
)

func Evaluate

func Evaluate(backend, value string, resume bool) Outcome

Evaluate applies the backend policy for a (backend, value, resume) combination using the generated Umpire Check function with backend and resume conditions. An empty value is always accepted. The outcome classification (UnsupportedCapability / UnsupportedValue / StartOnly) is derived from the generated Fair flag and the active branch.

type RuleMetaEntry

type RuleMetaEntry struct {
	Field    string
	RuleType string
	Expr     string
	Reason   string
}

RuleMetaEntry holds metadata about a rule for Challenge output.

type ThinkingPolicyAvailability

type ThinkingPolicyAvailability struct {
	Thinking                   FieldStatus
	ActiveThinkingPolicyBranch thinkingPolicyBranch `json:"-"`
}

ThinkingPolicyAvailability holds the availability status for each field.

type ThinkingPolicyConditions

type ThinkingPolicyConditions struct {
	Backend string `json:"backend"`
	Resume  bool   `json:"resume"`
}

ThinkingPolicyConditions holds the conditions for ThinkingPolicy availability checks.

type ThinkingPolicyFields

type ThinkingPolicyFields struct {
	Thinking *string `json:"thinking,omitempty"`
}

ThinkingPolicyFields holds the fields for ThinkingPolicy availability checks.

Jump to

Keyboard shortcuts

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