autosetup

package
v1.0.0-rc.13 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: Apache-2.0 Imports: 38 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 autosetup selects, installs, verifies, and configures native inference.

Index

Constants

This section is empty.

Variables

View Source
var Contract = servicecontract.Contract{
	ID:          "automatic-local-setup",
	Summary:     "Review and configure independent AI roles.",
	Description: "Choose local, remote or cloud routes for each role. Review connections, models, devices, settings and required downloads, then verify the selected group before saving it atomically.",
	Operations: []servicecontract.Operation{
		{
			ID: "plan", Summary: "Inspect the recommended local AI setup without changing the machine.", Description: "Reports the recommended roles, the artifacts they need and the repairs for what cannot be satisfied. Accepts an optional origin and refresh.",
			Spec: `Select a current curated, permissively licensed model that is curated as able
to run a multi-step tool loop, holding at least 32768 tokens of usable context
in this machine's memory. Capability gates the choice and context qualifies it:
a larger window on a model that cannot use it is not a capability. Selection
uses available memory, the model's native context ceiling, and the KV cache type
the worker is configured with (CONTENOX_LLAMA_KV_CACHE_TYPE; q8_0 halves what a
window costs in device memory). Cold/planner capacity does not count.
Origin restricts the model developer's region. Downloads use Hugging Face by
default (HF_ENDPOINT overrides it; HF_TOKEN optionally authenticates).

The worker and model are installed, a harmless tool call is verified, and only
then are native defaults saved. Subsequent runs reuse the configured eligible
model; --refresh selects again. Setup uses native inference.`,
			Output: servicecontract.Output{
				Stdout: "The machine's summary, the selected model with its download size, and the estimated hot context.",
				Format: "text, or the plan as JSON when --dry-run is given",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "a plan is produced", Meaning: "nothing was installed and no default changed"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "no curated model fits this machine's selection budget", Message: "names the budget, the KV cache type and the smallest model that would fit"},
			},
		},
		{
			ID: "apply", Summary: "Set up local AI", Description: "Acquire the recommended artifacts and verify real chat, completion and retrieval operations before saving all required role assignments.",
			Spec:   "Acquire the recommended artifacts and verify real chat, completion and retrieval operations before saving all required role assignments.",
			Inputs: []servicecontract.Input{{ID: "plan", Summary: "The reviewed plan whose roles are acquired, verified and saved", Type: "object", Required: true}},
			Output: servicecontract.Output{
				Stdout: "Acquisition progress, then the verified roles that were saved.",
				Stderr: "Progress narration for a long download.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "every required role is acquired and verified", Meaning: "the assignments are saved together"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "an artifact cannot be acquired", Message: "names the artifact and the failure; nothing is saved"},
				{When: "a role fails verification", Message: "names the role and the operation that failed; the current configuration is preserved"},
			},
		},
		{
			ID: "recommend", Summary: "Recommend roles independently across allowed connections.",
			Spec:   "Recommend a route for every role independently, across the connections the constraints allow, without changing any assignment.",
			Inputs: []servicecontract.Input{{ID: "recommendation", Summary: "Mode, origin and per-role connection constraints the recommendation must preserve", Type: "object", Required: true}},
			Output: servicecontract.Output{
				Stdout: "One recommendation per role with the connection it selects.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "every role has a recommendation", Meaning: "nothing was assigned"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "no allowed connection can serve a role", Message: "names the role and the constraint that excluded every connection"},
			},
		},
		{
			ID: "choose", Summary: "Select an alternative and recheck the group's resource and scheduling limits.",
			Spec: "Select an alternative route for one role and recheck the group's resource and scheduling limits, so a choice that cannot run with the others is refused before it is applied.",
			Inputs: []servicecontract.Input{
				{ID: "plan", Summary: "The reviewed plan the alternative is chosen from", Type: "object", Required: true},
				{ID: "role", Summary: "Role whose alternative is selected", Type: "string", Required: true, Values: inferencesetup.RoleIDs()},
				{ID: "alternative", Summary: "Index of the selected alternative", Type: "number"},
			},
			Output: servicecontract.Output{
				Stdout: "The selected alternative and the rechecked group.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "the alternative fits the group's limits", Meaning: "the plan now carries the chosen route"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "the alternative conflicts with another role's resources", Message: "names both roles and the resource they contend for"},
				{When: "the alternative index does not exist", Message: "names the range the plan offers"},
			},
		},
		{
			ID: "apply-recommended", Summary: "Acquire and verify the selected roles before committing them together.",
			Spec:   "Acquire and verify the selected roles before committing them together, so a partially available group is never saved as a configured one.",
			Inputs: []servicecontract.Input{{ID: "plan", Summary: "The reviewed plan whose selected roles are acquired and verified", Type: "object", Required: true}},
			Output: servicecontract.Output{
				Stdout: "Progress, then the roles that were verified and saved.",
				Stderr: "Progress narration for a long download.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "every selected role verifies", Meaning: "the assignments are saved together"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "a selected role fails verification", Message: "names the role and preserves the current configuration"},
			},
		},
		{
			ID: "prepare-local", Summary: "Install a native backend and prepare its local connection.",
			Spec: `Run the setup wizard to pick an LLM provider (native modeld, Ollama local or Cloud,
OpenAI, Anthropic, Gemini, Vertex AI, AWS Bedrock, or self-hosted vLLM), enter
credentials, and set defaults. This is the same wizard that runs inside IDE
terminals via ACP.

Examples:
  contenox-runtime setup`,
			Inputs: []servicecontract.Input{{ID: "nativePrerequisite", Summary: "The explicitly selected native backend, whose backend field is llama or openvino", Type: "object", Required: true}},
			Examples: []servicecontract.Example{
				{Command: "contenox-runtime setup", Explanation: "The interactive journey."},
				{Command: "contenox-runtime auto", Explanation: "The same installation driven from the machine's own plan."},
			},
			Output: servicecontract.Output{
				Stdout: "The wizard's questions, then the defaults it saved.",
				Stderr: "The refusal when the run is not interactive.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "the wizard completes or the operator quits", Meaning: "a quit keeps the current configuration"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "no input arrives because the run is not interactive", Message: "says the wizard is interactive, names errSetupNoInput, and points at 'contenox-runtime config set' for a non-interactive run"},
				{When: "a store the settings name cannot be used", Message: "names the store and refuses before offering a wizard whose answers cannot be saved"},
			},
		},
		{
			ID: "devices", Summary: "List the devices and memory pools local inference can use.",
			Description: "Read, for every local connection, the devices it reports, the memory pool each draws on, the pool's size and free memory, and the ceiling its owner enforces.",
			Spec:        "List what local inference can use on this computer: for each local connection its devices grouped by the memory pool they draw on, each pool's total and free memory, and the ceiling the connection's owner enforces on it. A connection that cannot be read is listed with the reason. The pool names are the ones the ceiling operation accepts.",
			Output: servicecontract.Output{
				Stdout: "Per connection: its pools with size, free memory and ceiling, and the devices in each pool.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "the connections are read", Meaning: "each listed pool can be bounded with a ceiling"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "no local connection is saved", Message: "names the step that prepares local inference"},
			},
		},
		{
			ID: "configure-ceiling", Summary: "Bound what local inference may hold on one memory pool.",
			Description: "Set the share of one memory pool's total bytes a native connection's owner lets local inference hold. Roles already placed on the pool are checked and reported, never required to be verified first.",
			Spec:        "Set the device ceiling of one memory pool on a native connection's owner, as a share of the pool's total bytes greater than 0 and at most 1. The owner enforces the new limit when it next admits a model. Lowering a ceiling never requires the connection's roles to be verified: the result names the roles whose verified placements together hold more than the new limit and the roles whose placement is not verified, so their fit is unknown, and each is repaired by choosing its model again.",
			Inputs: []servicecontract.Input{
				{ID: "id", Summary: "The native connection whose owner enforces the ceiling", Type: "string", Required: true},
				{ID: "poolId", Summary: "The memory pool the ceiling bounds, as the connection's device list names it", Type: "string", Required: true},
				{ID: "share", Summary: "The share of the pool's total bytes local inference may hold, greater than 0 and at most 1", Type: "number", Required: true},
			},
			Output: servicecontract.Output{
				Stdout: "The ceilings the connection's owner enforces after the change, and the roles that no longer fit or cannot be checked.",
				Format: "text",
			},
			Outcomes: []servicecontract.Outcome{
				{Code: 0, When: "the owner accepts the limit", Meaning: "the owner enforces the new ceiling; roles listed as not fitting are repaired by choosing a smaller model for them"},
			},
			Refusals: []servicecontract.Refusal{
				{When: "models loaded on the pool already hold more than the ceiling allows", Message: "names the pool and the limit; the previous ceiling stays in force"},
				{When: "the connection is not native or reports no such pool", Message: "names the connection or the pool"},
			},
		},
	},
}

Contract describes independent inference recommendations and their application.

Functions

func EnsureLocalConnection

func EnsureLocalConnection(ctx context.Context, db libdb.DBManager) (string, error)

EnsureLocalConnection returns a route to this machine even when other Modeld nodes are connected to the same Runtime.

func Fingerprint

func Fingerprint(plan Plan) (string, error)

Fingerprint identifies a plan by its content. A nil collection and an empty one fingerprint identically, because a plan echoed back through a wire that cannot tell them apart must still match the plan the planner answered.

func ImportanceIDs

func ImportanceIDs() []string

ImportanceIDs returns the declared importance vocabulary, highest first.

func SetInitialModel

func SetInitialModel(ctx context.Context, db libdb.DBManager, model string) error

SetInitialModel makes an acquired native model the first chat default only when the operator has not selected a provider or model.

func Verify

func Verify(ctx context.Context, model modelregistry.ModelDescriptor, planned int, kvCacheType string, progress io.Writer) (int, error)

Verify requires a native tool call and a usable measured context window.

Types

type CandidateChoice

type CandidateChoice string

CandidateChoice selects which qualified candidate an importance level takes first.

const (
	// ChoiceLargest prefers the largest context, then the largest allocation.
	ChoiceLargest CandidateChoice = "largest"
	// ChoiceDocumented keeps the role's documented candidate order.
	ChoiceDocumented CandidateChoice = "documented"
	// ChoiceSmallest prefers the smallest context, then the smallest allocation.
	ChoiceSmallest CandidateChoice = "smallest"
)

type CeilingResult

type CeilingResult struct {
	Ceilings   []PoolCeiling `json:"ceilings"`
	Connection string        `json:"connection"`
	PoolID     string        `json:"poolId"`
	PoolLabel  string        `json:"poolLabel"`
	LimitBytes int64         `json:"limitBytes"`
	TotalBytes int64         `json:"totalBytes"`
	HeldBytes  int64         `json:"heldBytes"`
	Unfit      []RoleMemory  `json:"unfit"`
	Unchecked  []RoleMemory  `json:"unchecked"`
}

CeilingResult is what a ceiling change leaves in force on a native connection. Unfit lists the roles whose verified placements together hold more of the pool than the new limit, and Unchecked the roles on the connection whose placement is not verified, so their fit is unknown.

type DeviceView

type DeviceView struct {
	ID          string   `json:"id"`
	Label       string   `json:"label"`
	Type        string   `json:"type"`
	Backend     string   `json:"backend"`
	State       string   `json:"state"`
	Error       string   `json:"error,omitempty"`
	Operations  []string `json:"operations"`
	MemoryBytes int64    `json:"memoryBytes"`
}

DeviceView is one device a native connection reports.

type HostDevices

type HostDevices struct {
	ConnectionID string       `json:"connectionId"`
	Connection   string       `json:"connection"`
	Endpoint     string       `json:"endpoint"`
	Error        string       `json:"error,omitempty"`
	HostThreads  int          `json:"hostThreads"`
	Pools        []PoolView   `json:"pools"`
	Unpooled     []DeviceView `json:"unpooledDevices"`
}

HostDevices is what the planner sees on one native connection.

type Importance

type Importance string

Importance is how much a person values a role against the other roles sharing its memory pools. An absent importance plans the role as ImportanceNormal.

const (
	// ImportanceLow plans the role last and takes its smallest qualified candidate.
	ImportanceLow Importance = "low"
	// ImportanceNormal keeps the documented planning order and candidate choice.
	ImportanceNormal Importance = "normal"
	// ImportanceHigh plans the role first and takes its largest qualified candidate.
	ImportanceHigh Importance = "high"
)

type ImportanceRule

type ImportanceRule struct {
	Importance           Importance      `json:"importance"`
	Rank                 int             `json:"rank"`
	Choice               CandidateChoice `json:"choice"`
	MinChatContextTokens int             `json:"minChatContextTokens"`
	HeadroomFrac         float64         `json:"headroomFrac"`
}

ImportanceRule is the planning data one importance level selects. Rank orders pool consumption, lowest first; MinChatContextTokens is the smallest context a Chat or Recovery candidate qualifies with; HeadroomFrac is the share of a worker's memory budget kept free above its estimated allocation.

func ImportanceRules

func ImportanceRules() []ImportanceRule

ImportanceRules returns the planning data of every importance level, highest first.

type NativeHost

type NativeHost struct {
	ConnectionID string              `json:"connectionId"`
	Inventory    transport.Inventory `json:"inventory"`
	Resources    admission.Resources `json:"resources"`
	Error        string              `json:"error,omitempty"`
}

NativeHost is an endpoint-scoped inventory and owner-confirmed residency observation.

type NativePrerequisite

type NativePrerequisite struct {
	Backend string `json:"backend"`
}

NativePrerequisite selects an explicitly requested local backend installation.

type Options

type Options struct {
	Origin        string
	Backend       string
	KVCacheType   string
	DataRoot      string
	WorkerBaseURL string
	Refresh       bool
	Progress      io.Writer
	Report        func(Progress) error
}

Options controls native setup selection and artifact acquisition.

type Plan

type Plan struct {
	Roles               []RolePlan                      `json:"roles,omitempty"`
	Mode                string                          `json:"mode,omitempty"`
	Baseline            []PoolEstimate                  `json:"baseline,omitempty"`
	Models              []modelregistry.ModelDescriptor `json:"models"`
	Hardware            modelhardware.Hardware          `json:"hardware"`
	Model               modelregistry.ModelDescriptor   `json:"model"`
	Backend             string                          `json:"backend"`
	Reused              bool                            `json:"reused"`
	EstimatedHotContext int                             `json:"estimatedHotContext"`
	Fingerprint         string                          `json:"fingerprint"`
	Assignments         []PlannedRole                   `json:"assignments"`
	Ceilings            []PoolCeiling                   `json:"ceilings,omitempty"`
}

Plan is the automatic native setup selected for one machine. Ceilings are the device ceilings a role recommendation was planned under.

func Evaluate

func Evaluate(request RecommendationRequest, input PlanningInput) (Plan, error)

Evaluate ranks completion protection before Chat capacity and retrieval while accounting for each host pool independently.

type PlannedRole

type PlannedRole struct {
	Role     string `json:"role"`
	Provider string `json:"provider"`
	Model    string `json:"model"`
}

PlannedRole is one required IDE capability served by the reviewed automatic plan.

type PlanningInput

type PlanningInput struct {
	Configuration inferencesetup.Configuration
	Artifacts     []modelregistry.ModelDescriptor
	Hosts         []NativeHost
}

PlanningInput contains configuration, artifact contracts and host observations without credentials.

type PoolCeiling

type PoolCeiling struct {
	ConnectionID string  `json:"connectionId"`
	PoolID       string  `json:"poolId"`
	Share        float64 `json:"share"`
}

PoolCeiling bounds what local inference may hold on one connection's memory pool, as a share of the pool's total bytes (0 < Share <= 1).

type PoolEstimate

type PoolEstimate struct {
	Host           string `json:"host"`
	PoolID         string `json:"poolId"`
	Bytes          int64  `json:"bytes"`
	AvailableBytes int64  `json:"availableBytes"`
	CeilingBytes   int64  `json:"ceilingBytes,omitempty"`
}

PoolEstimate scopes a reservation to its owner's host and physical memory pool. CeilingBytes is the pool's device ceiling in bytes, absent when the pool has none.

type PoolView

type PoolView struct {
	ID             string       `json:"id"`
	Label          string       `json:"label"`
	Kind           string       `json:"kind"`
	State          string       `json:"state"`
	Error          string       `json:"error,omitempty"`
	TotalBytes     int64        `json:"totalBytes"`
	AvailableBytes int64        `json:"availableBytes"`
	Share          float64      `json:"share"`
	Bounded        bool         `json:"bounded"`
	Devices        []DeviceView `json:"devices"`
}

PoolView is one memory pool a native connection reports, with the devices that draw on it and the ceiling its owner enforces.

type Progress

type Progress struct {
	Phase   string
	Message string
	Current int64
	Total   int64
}

Progress reports one automatic setup phase and its optional byte position.

type RecommendationRequest

type RecommendationRequest struct {
	Mode        string           `json:"mode"`
	Origin      string           `json:"origin"`
	Constraints []RoleConstraint `json:"constraints"`
	Ceilings    []PoolCeiling    `json:"ceilings,omitempty"`
}

RecommendationRequest chooses local, cloud or mixed candidates and independent role constraints. Ceilings replace, per connection and pool, the device ceilings the connection's owner reports, so a plan can be previewed under limits not yet saved.

type Result

type Result struct {
	Plan       Plan `json:"plan"`
	HotContext int  `json:"hotContext"`
}

Result is a verified native setup.

type RoleCandidate

type RoleCandidate struct {
	CompletionMode    string                         `json:"completionMode,omitempty"`
	ThreadLimit       int                            `json:"threadLimit"`
	Route             inferencesetup.RouteProposal   `json:"route"`
	ConnectionID      string                         `json:"connectionId"`
	Endpoint          string                         `json:"endpoint"`
	Native            bool                           `json:"native"`
	Installed         bool                           `json:"installed"`
	SharedMemory      bool                           `json:"sharedMemory"`
	Artifact          *modelregistry.ModelDescriptor `json:"artifact,omitempty"`
	Pools             []PoolEstimate                 `json:"pools"`
	ContextTokens     int                            `json:"contextTokens"`
	Scheduling        string                         `json:"scheduling"`
	Reason            string                         `json:"reason"`
	Verified          bool                           `json:"verified"`
	ReviewError       string                         `json:"reviewError,omitempty"`
	ExecutionSettings modeldconn.WorkerOptions       `json:"executionSettings"`
}

RoleCandidate describes an editable route, its prerequisites and conservative allocation estimate.

type RoleConstraint

type RoleConstraint struct {
	Role               string                          `json:"role"`
	Policy             string                          `json:"policy"`
	ConnectionID       string                          `json:"connectionId,omitempty"`
	AllowedConnections []string                        `json:"allowedConnections"`
	Inputs             inferencesetup.InputRequirement `json:"inputs"`
	ExecutionMode      string                          `json:"executionMode"`
	Importance         Importance                      `json:"importance,omitempty"`
}

RoleConstraint selects one recommendation policy without changing the live assignment.

type RoleMemory

type RoleMemory struct {
	Role     string `json:"role"`
	Name     string `json:"name"`
	Provider string `json:"provider"`
	Model    string `json:"model"`
	Bytes    int64  `json:"bytes"`
}

RoleMemory is one assigned role and the bytes its verified placement holds on a memory pool; Bytes is zero when the placement has not been verified.

type RolePlan

type RolePlan struct {
	Constraint   RoleConstraint  `json:"constraint"`
	State        string          `json:"state"`
	Selected     *RoleCandidate  `json:"selected,omitempty"`
	Alternatives []RoleCandidate `json:"alternatives"`
	Repairs      []string        `json:"repairs"`
}

RolePlan keeps one role's result available even when another role is unresolved.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service owns automatic native setup independently of a presentation surface.

func New

New constructs automatic setup over the persistent runtime database.

func NewPlanner

func NewPlanner(tracker libtracker.ActivityTracker) (*Service, error)

NewPlanner constructs read-only automatic selection without persistent reuse.

func (*Service) Apply

func (s *Service) Apply(ctx context.Context, plan Plan, opts Options) (Result, error)

Apply installs and verifies a plan before saving it as the native default.

func (*Service) ApplyAll

func (s *Service) ApplyAll(ctx context.Context, plan Plan, opts Options, roles *inferencesetup.Service) (Result, error)

ApplyAll acquires the reviewed artifacts and verifies every production role before atomically persisting assignments.

func (*Service) ApplyRecommended

func (s *Service) ApplyRecommended(ctx context.Context, plan Plan, selected []string, opts Options, roles *inferencesetup.Service, acquisition *modelacquisition.Service) (Result, error)

ApplyRecommended acquires and verifies the explicitly selected roles before committing them as one group.

func (*Service) Choose

func (s *Service) Choose(plan Plan, role string, alternative int) (Plan, error)

Choose replaces one selection with a displayed alternative and rechecks the group's resource and scheduling constraints.

func (*Service) ConfigureCeiling

func (s *Service) ConfigureCeiling(ctx context.Context, setup *inferencesetup.Service, ceiling PoolCeiling) (CeilingResult, error)

ConfigureCeiling sets one memory pool's device ceiling on a native connection's owner and reports what it leaves in force. Lowering a ceiling never requires the connection's roles to be verified: the owner enforces the new limit on its next admission, and the result names the roles whose verified placements no longer fit and the roles whose fit is unknown. The owner refuses a limit below what its loaded workers already hold.

func (*Service) Devices

func (s *Service) Devices(ctx context.Context, setup *inferencesetup.Service) ([]HostDevices, error)

Devices reads the devices and memory pools the planner sees on every native connection, with the ceiling each pool carries. A connection that cannot be read is reported with its error rather than omitted.

func (*Service) Plan

func (s *Service) Plan(ctx context.Context, opts Options) (Plan, error)

Plan selects a compatible curated model without changing the machine.

func (*Service) PrepareLocal

PrepareLocal installs the selected native backend and registers an unambiguous local connection without assigning roles.

func (*Service) Previous

func (s *Service) Previous(ctx context.Context, origin, backend string, budget int64, kvCacheType string) (modelregistry.ModelDescriptor, bool, error)

Previous returns a configured automatic model when it remains eligible.

func (*Service) Recommend

func (s *Service) Recommend(ctx context.Context, setup *inferencesetup.Service, request RecommendationRequest) (Plan, error)

Recommend reads independent connection observations before evaluating role constraints.

func (*Service) SaveDefaults

func (s *Service) SaveDefaults(ctx context.Context, model modelregistry.ModelDescriptor) error

SaveDefaults makes a verified native model the chat and recovery default.

Jump to

Keyboard shortcuts

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