setup

package
v0.14.1 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2026 License: MIT Imports: 21 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 setup routes one Codex home through a stage 2 edge and brain (codex-router setup), and undoes it. It edits the home's config.toml in marked blocks (plan M10) with the router provider and its token header (M9), stores the provider port and token in the home's state dir, and installs that home's service units through internal/service.

Index

Constants

View Source
const ConfigFile = "config.toml"

ConfigFile is Codex's config in a home.

View Source
const PluginEnvFile = "codex-router.env"

PluginEnvFile, in a Codex home, tells the codex-router plugin's scripts the binary and the state base setup used, as KEY=value lines. Codex runs plugin hooks with the env of whichever shell started the home's daemon, which may have neither on PATH or in XDG_STATE_HOME.

Variables

This section is empty.

Functions

func AddProvider

func AddProvider(src []byte, p Provider) ([]byte, error)

AddProvider returns src with the router selected as model_provider and its provider table appended, both in marked blocks; blocks from an earlier setup are replaced. The rest of the file, comments included, stays byte for byte. It refuses a file that does not parse, sets model_provider itself, or already defines the router provider. The result is checked with a TOML parser: it must select the router and decode to the same settings as src otherwise.

func Diff

func Diff(a, b []byte) string

Diff returns the line changes from a to b as hunks: a "@@ -i +j @@" header (1-based lines), then "-" and "+" lines. Token values are redacted. Setup only inserts and removes whole blocks, so a greedy resync is enough: it always yields a correct edit, and a minimal one for block edits.

func RemoveBlocks

func RemoveBlocks(src []byte) ([]byte, bool, error)

RemoveBlocks returns src without setup's marked blocks, and whether it had any. A block without its end marker is an error: the file was edited by hand and the block's extent is unknown.

func Run

func Run(ctx context.Context, o Options) error

Run sets the home up, or undoes it with Options.Undo. It prints the resolved home first, then each change. Setup installs and loads the units before it writes config.toml, so Codex never points at a port nothing holds; undo restores config.toml before it removes the units.

Types

type Options

type Options struct {
	Home home.Home
	// HomePath is the home as the user gave it (home.Given), symlinks kept.
	// The units get it as --home, so they resolve the same Home.Name.
	HomePath string
	// StateDir is the absolute state base, as $XDG_STATE_HOME; the units
	// get it as --state-dir.
	StateDir string
	// Config is the codex-router config the units load; empty lets them
	// use their default.
	Config string
	// Bin is the codex-router binary the units run.
	Bin string
	// DryRun prints what would change and writes nothing.
	DryRun bool
	// Undo removes the config blocks and the units; Purge also deletes the
	// home's state dir.
	Undo, Purge bool
	// FollowSymlink allows editing a symlinked config.toml's target, where
	// the token then lands (plan M9).
	FollowSymlink bool
	Service       *service.Manager
	Out           io.Writer
	// Now stamps backups; FreePort picks a port. Tests replace them.
	Now      func() time.Time
	FreePort func() (int, error)
}

Options configure Run.

type Provider

type Provider struct {
	Port  int
	Token string
}

Provider is the router provider setup writes into a home's config.toml.

Jump to

Keyboard shortcuts

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