layered

package
v0.17.0 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 17 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 layered is the one layered configuration resolver: a value is taken from the invocation's flag, else the repository's committed file, else the machine's file under ~/.abcd.noindex/, else the bundled default the caller supplies, and it comes back with the layer and the origin that supplied it.

It is the canonical primitive for every configuration that more than one party may set (the one-canonical-primitive rule): the model-tier routing table (itd-2609170822093401, internal/core/oracle), the pace and the sub-agent ceiling (itd-2609201925079472, pace.*), the RepoPrompt review route (itd-6, oracle.review), the runner per role (itd-2609201916056194, roles.<role>.runner), the duplicate-match threshold (itd-2609212137116617, match.threshold), how a plain-Terminal interview takes a choice from a list (itd-2610030810370060, interview.list), and the build loop's review set and model-class map (itd-2610240922461281, review.* and models.classes, the map, each class's effort models.effort (itd-2611101419006280) and the ceiling read from the machine layer alone), and the layout limits of abcd's questions (itd-2610301914350541, question.*, the machine layer admitted only where it tightens). A consumer reads through it rather than opening a file of its own, so the precedence order, the guarded reads and the refusals are spelled once.

Two file families, one shape of resolution (dcn-2609250000000005):

  • Config: .abcd/config.json in the checkout and ~/.abcd.noindex/config.json on the machine, holding scalar keys under a namespace (pace.work_minutes, oracle.review, roles.<role>.runner, match.threshold). The repository file is shared with the keys ahoy writes (docs, meta, oracle.backend, repo, attribution, rules), so no reader owns the whole file: a consumer CLAIMS its namespace and every key in it, and an unknown key under a claimed namespace is refused.
  • OracleRouting: .abcd/config/oracle-routing.json and ~/.abcd.noindex/oracle-routing.json, the per-agent routing table the model-tier intent names. It carries a top-level schema_version, and its reader claims the whole file.

Loudness is the contract (the loud-staging rule applied to configuration). An absent file is an absent layer, the ordinary case. Every other fault is an error naming the file: a present file that is not a regular file, is a symlink or sits behind one, is writable by others (machine layer), is not valid JSON, holds a key twice, carries trailing content, or declares the wrong schema_version; an unknown key under a claimed namespace, or the namespace itself spelt in another case or written with a key below it as one dotted member; a value in the winning layer that does not decode to the caller's type or fails its check. None of these falls through to a lower layer or to the default, because a configuration that silently does less than it says is the failure this package exists to close.

The package reads and never writes, never reaches a network, and never prints: the front door renders its values and its errors.

Index

Constants

View Source
const (
	InterviewListKey      = "interview.list"
	InterviewListArrows   = "arrows"
	InterviewListNumbered = "numbered"

	InterviewRedraftsKey = "interview.redrafts"
	// InterviewRedraftsDefault is the bound when no file sets it.
	InterviewRedraftsDefault = 3
	// InterviewRedraftsMax is the highest bound a repository may set; 0, the
	// lowest, shows a refused question at once.
	InterviewRedraftsMax = 10
)

The interview namespace holds two keys, each one party's to set.

interview.list (spc-2610030911534855, "The numbered fallback"): how a plain-Terminal interview takes a choice from a list. arrows, the bundled default, is the arrow-key list with typing to narrow; numbered reads whole lines, a number or part of a name, and never touches the terminal's modes, which is the mode a screen reader is served by. It is the machine's alone.

interview.redrafts (iss-2611011402496418, dcn-2611012123240576): how many times in a row an AI-written interview hands a question or a done outcome abcd's check refused back to its interviewer to redraft, before it shows the question as it stands, repaired where it can be, or ends on the outcome. It is the repository's alone.

View Source
const (
	// SlugCapKey is the key a repository sets its cap under in .abcd/config.json.
	SlugCapKey = "records.slug_cap"
	// MinSlugCap is the least a cap may be: a shorter slug names too little to
	// tell one record from the next.
	MinSlugCap = 16
	// MaxSlugCap is the most a cap may be: a filename stops at 255 bytes on every
	// filesystem abcd runs on, and the id, its family tag, the extension and a
	// temporary name's suffix come on top of the slug.
	MaxSlugCap = 200
)

The records namespace: how long a record's slug may be in this repository.

View Source
const MaxFileBytes = 1 << 20

MaxFileBytes caps every layer's read. A configuration file is a few hundred bytes; 1 MiB bounds a planted device or an endless file without ever refusing a real one.

Variables

View Source
var (
	// Config is the shared scalar-key file (see the package doc).
	Config = File{RepoRel: ".abcd/config.json", MachineRel: "config.json"}
	// OracleRouting is the per-agent model-tier routing table.
	OracleRouting = File{RepoRel: ".abcd/config/oracle-routing.json", MachineRel: "oracle-routing.json", SchemaVersion: 1}
)

Functions

func BoundKey

func BoundKey(s string) string

BoundKey renders a key or a name for a message, bounded like compact bounds a value: a file may be MaxFileBytes long, and a key it carries must not reach a refusal, a diagnostic or a stderr line whole (review-tier1 F1). It cuts on a rune boundary, so the result stays valid UTF-8.

func Decode

func Decode[T any](raw json.RawMessage) (T, error)

Decode is Get's strict decode, exported so a consumer that selects among Lookup's layers itself (the routing table's activation rule) decodes with the same strictness.

func RecordSlugCap added in v0.17.0

func RecordSlugCap(repoRoot string) (int, error)

RecordSlugCap is the one value every record-minting verb cuts a slug at and every check of a committed record's slug holds it to: records.slug_cap in repoRoot's .abcd/config.json, else recordid.DefaultMaxSlugLen. A value that is not a whole number within the bounds, a misspelt key under records, and a file that cannot be read each refuse, naming the file, and a caller mints nothing.

It reads the repository layer alone, so a machine's file sets nothing here. The cap bounds names committed for every clone, and a figure one person's machine held would mint a record another clone's check refuses.

func SwapUserHomeForTest added in v0.13.3

func SwapUserHomeForTest(fn func() (string, error)) (restore func())

SwapUserHomeForTest substitutes the home lookup RootsFor reads the machine layer through and returns the restore. It is exported because the front-door tests that load layered files live in another package. Tests only; never called in production code, and never safe to call from a parallel test.

Types

type File

type File struct {
	// RepoRel is the slash path relative to the checkout root.
	RepoRel string
	// MachineRel is the slash path relative to ~/.abcd.noindex/.
	MachineRel string
	// SchemaVersion, when non-zero, is the top-level schema_version every
	// layer's file must declare.
	SchemaVersion int
}

File names one configuration file family: where it sits in a checkout and where it sits under ~/.abcd.noindex/.

func (File) MachineOrigin

func (f File) MachineOrigin() string

func (File) RepoOrigin

func (f File) RepoOrigin() string

RepoOrigin and MachineOrigin are how a layer's file is named in a value's origin and in every refusal: repo-relative, and in the tilde form so no message carries the caller's home path.

type Found

type Found struct {
	Layer  Layer
	Origin string
	Raw    json.RawMessage
}

Found is one layer's raw value for a key.

type KeyRefusedError added in v0.16.1

type KeyRefusedError struct {
	Key string
	// Value is the value as the file holds it, compacted and bounded.
	Value  string
	Bounds question.Bound
	// Layer and Origin name the file that holds Value.
	Layer  Layer
	Origin string
	// NotInteger marks a value that does not decode as a whole number.
	NotInteger bool
	// Limit and LimitOrigin are set for a personal value that loosens: the
	// limit otherwise in force and the file that set it ("bundled" for the
	// default).
	Limit       int
	LimitOrigin string
}

KeyRefusedError is a question value read and refused: outside its bounds, not a whole number, or, for a personal value, looser than the limit otherwise in force (LimitOrigin set). Nothing falls through to a lower layer or to the default (itd-2610301914350541 decision 7).

func (*KeyRefusedError) Error added in v0.16.1

func (e *KeyRefusedError) Error() string

func (*KeyRefusedError) Loosens added in v0.16.1

func (e *KeyRefusedError) Loosens() bool

Loosens reports whether the refusal is a personal value above the limit in force, rather than a value outside its bounds.

type Layer

type Layer int

Layer is where a resolved value came from. The constants ascend in precedence: a higher layer holding a key beats every lower one.

const (
	// None: no layer holds the key and no bundled value applies. Only a
	// consumer with its own activation rule reports it (the routing table
	// applies nothing until a table is accepted).
	None Layer = iota
	// Bundled: the default the binary ships, supplied by the caller.
	Bundled
	// Machine: the file under ~/.abcd.noindex/.
	Machine
	// Repo: the file committed in the checkout the session resolved.
	Repo
	// Flag: the invocation's own override, for one run.
	Flag
)

func (Layer) String

func (l Layer) String() string

String is the layer's name as every surface renders it.

type LimitSource added in v0.16.1

type LimitSource struct {
	Key    string
	Layer  Layer
	Origin string
}

LimitSource is where the figure in force for one key came from: the bundled default, the repository's file, or the machine's file where a personal value tightened it.

type QuestionLimitsValue added in v0.16.1

type QuestionLimitsValue struct {
	Value[question.Limits]
	Sources []LimitSource
}

QuestionLimitsValue is the resolved limits: Value carries them, with the Layer and Origin of the loosest layer that set any key (the repository's over the machine's, since the machine may only tighten; bundled where no file set one), and Sources the provenance of each key, in question.Bounds' order, which is what the check's limits_source reports key by key.

func QuestionLimits added in v0.16.1

func QuestionLimits(r Roots) (QuestionLimitsValue, error)

QuestionLimits resolves the three question keys over question.Default. It claims the question namespace, so any other key under it (question.options, question.columns, a misspelt one) is refused by Claim naming the key and the file. Each key's limit otherwise in force is the repository's value where .abcd/config.json sets it, else the default; a machine value at or below that limit replaces it, and one above it is refused naming both figures and their files (itd-2610301914350541 decision 5). Every value found, in either file, is decoded strictly as an int and held to its question.Bound before any comparison, so a personal value below the floor is refused naming the bounds, never the limit.

It returns one of three states: the defaults (no key set, Layer Bundled), the limits in force with the file that set each, or an error. An error is an *UnreadError where a layer could not be read, returned with the defaults, since the gate fails open and loud on it and the question runs at them; and a refusal otherwise (*KeyRefusedError, or Claim's unknown key), returned with the zero value, since the gate fails closed and nothing falls through.

func (QuestionLimitsValue) Note added in v0.17.0

Note is where the limits came from, as the asking rules say it (question.AskingRulesFrom): one origin per key, in question.Bounds' order, where any file set a figure, and the zero note where every key is bundled.

func (QuestionLimitsValue) SetByFile added in v0.16.1

func (v QuestionLimitsValue) SetByFile() bool

SetByFile reports whether any key's figure came from a file.

type Roots

type Roots struct {
	Repo string
	Home string
	// HomeRefused marks a home RootsFor declined (iss-2609300012273350): Home
	// is "" so nothing is read from or written to it, and the machine layer
	// reads as absent instead of failing the load. RootsFor's notes say why.
	HomeRefused bool
	// RepoAt, when set, is the commit (a full object name) the repository
	// layer is read at, from the object store of the repository at Repo,
	// never from its working tree; RepoAtName names it in every origin and
	// refusal ("origin/main"). The merge gate reads facilitator.mode this way
	// at the default branch's tip, so a branch that commits its own value, or
	// deletes the default branch's, does not decide the gate for itself
	// (dcn-2610230058333177).
	RepoAt     string
	RepoAtName string
	// RepoAtAsStored reads the repository layer at RepoAt as the object store
	// holds it (gitutil.RunCappedBytesAsStoredContext: no replace ref stands
	// one tree or blob in for another), for a reader whose every other read of
	// history is as stored. false, the zero value every other reader leaves it
	// at, reads it as git resolves it.
	RepoAtAsStored bool
}

Roots are the two places the layers are read from. Repo is the directory the repository layer is read at; "" means there is none and the repo layer is absent. Home is the caller's home directory; "" is refused, because an unresolved home would drop the machine layer without a word. A front door builds Roots with RootsFor; a test builds them by hand.

func HomeRoots added in v0.16.0

func HomeRoots() (Roots, string)

HomeRoots is RootsFor without the repository: the machine layer of the caller's own home, judged by MachineRoots, and the note it made. It asks git nothing, so a reader that names its repository itself (readFacilitatorAt's callers) and runs under a deadline resolves its home with no unbounded git.

func MachineRoots added in v0.15.1

func MachineRoots(home string) (Roots, string)

MachineRoots is the Roots of a reader of the machine layer alone (Repo is ""), the one way such a reader resolves the home it was given: judged by the rule RootsFor applies (gitutil.HomeInsideWorkingTree), so a home inside a git working tree that is not the account's own is declined, HomeRefused makes Load read the machine layer as absent, and note says why, for the caller to put on stderr. A home outside every working tree, and "", are passed through with no note.

func RootsFor

func RootsFor(cwd string) (Roots, []string)

RootsFor is the one way a front door resolves Roots for a working directory, so every consumer of a layered file (the bare board, the delegating verbs' --route, and the pace, runner, review-route and match-threshold readers that follow) reads the repository layer from the same place.

The repository root is the rules loader's (rules.Resolve), not git's toplevel, and that is the choice for a reason: .abcd/rules.json, .abcd/guard.json and .abcd/config.json are already read from that root, so a session's injected rules, its shell guard and its layered configuration can never come from two different directories. The two answers differ in two places, and the rules root is the right one in both: a nested .abcd/ inside the working tree (a monorepo member governs its own subtree, as it already does for its rules), and a repository git will not answer for, where the rules root is bounded by the same shape check and ownership gate (a foreign- uid checkout falls back to the working directory with a note, instead of being read on git's say-so or dropped without one). Outside any repository it is the working directory, walked no higher, exactly as the rules loader reads it.

notes are the resolution's refusals (a foreign-owned checkout declined), for the front door to print on stderr; the home is left "" when it cannot be resolved, which Load refuses loudly.

A home inside a git working tree that is not the account's own is refused (iss-2609300012273350), by the one rule gitutil.HomeInsideWorkingTree spells for the credential store too. The home is $HOME, and an environment the repository can shape (a committed harness settings file whose env block sets HOME into the tree) would otherwise let the checkout supply the machine layer, the layer that decides which route may spend the person's paid key. The tree a checkout controls is never this machine's layer, unless it is the home the account database names for this uid (a dotfiles-in-HOME account), judged by file identity. Home is left "" so nothing is read from or written to it, HomeRefused makes Load read the machine layer as absent rather than fail, and a note says why. A home outside every working tree (every test and CI job's temporary HOME among them) is untouched.

type Stack

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

Stack is one file family's loaded layers.

func Load

func Load(f File, r Roots) (*Stack, error)

Load reads the repo and machine layers of f. The flag layer starts empty and is filled with SetFlag.

func LoadContext added in v0.16.0

func LoadContext(ctx context.Context, f File, r Roots) (*Stack, error)

LoadContext is Load with the git questions a repository layer read at a commit asks (r.RepoAt) bounded by ctx: a git still running when ctx ends is killed, and the load fails with ctx's error wrapped. The status line reads facilitator.mode this way, inside its own deadline.

func (*Stack) Claim

func (s *Stack) Claim(namespace string, keys ...string) error

Claim declares that the caller owns namespace and that keys are every key it may hold, in every layer. An unknown key is refused, naming the key, the file it sits in and the keys the namespace takes, so a misspelt key never lets a default apply unannounced. namespace "" claims the file's top level (a file one reader owns outright); a "*" segment claims every member at that level (roles.* claims each role's keys, whatever the role is called). A named segment spelt in another case in any layer ("Facilitator" for facilitator), or written with a key below it as one dotted member ("facilitator.mode"), is refused too, since Lookup would ignore it and a lower layer would decide. A namespace no layer holds is not an error.

func (*Stack) Lookup

func (s *Stack) Lookup(key string) ([]Found, error)

Lookup returns every layer that holds key, highest precedence first, so the winner is the first entry and a board can render the rest beside it. A path that runs through a non-object value is an error naming the layer's file.

func (*Stack) Members

func (s *Stack) Members(l Layer, key string) ([]string, error)

Members returns the member names of the object at key in one layer, sorted. An absent layer or key returns nil; a non-object value is an error.

func (*Stack) Present

func (s *Stack) Present(l Layer) bool

Present reports whether the layer's file exists (repo, machine) or any flag was set (flag).

func (*Stack) SetFlag

func (s *Stack) SetFlag(key string, v any, origin string) error

SetFlag places v at key in the flag layer, for this invocation only. origin is the flag text as typed (for example "--pace 90/240"), which becomes the value's origin and is how a receipt names an override verbatim.

type UnreadError added in v0.16.1

type UnreadError struct {
	// Origin names the file in the tilde or repo-relative form every refusal
	// uses.
	Origin string
	// Err is the whole message, the text Load returned before the type
	// existed, wrapping the cause.
	Err error
}

UnreadError is a layer Load could not read or parse: a file that is a symlink or not a regular file, one behind a symlinked directory, writable by others or owned by another account (machine layer), one that is not a single JSON object, and an unresolved home. Everything after a successful load (an unknown key Claim refuses, a value Get or a resolver refuses) is a refusal of a value read, not an UnreadError, so a caller tells the two apart with errors.As and never by reading words: on the first the question gate checks abcd's question at the defaults, loudly, naming the file, and on the second it refuses abcd's question (itd-2610301914350541 decisions 7 and 8).

func (*UnreadError) Error added in v0.16.1

func (e *UnreadError) Error() string

func (*UnreadError) Unwrap added in v0.16.1

func (e *UnreadError) Unwrap() error

type Value

type Value[T any] struct {
	V      T
	Layer  Layer
	Origin string
}

Value is a resolved configuration value with its provenance.

func Get

func Get[T any](s *Stack, key string, bundled T, check func(T) error) (Value[T], error)

Get resolves key to a T: the highest layer holding it, else bundled. The winning layer's value must decode strictly into T (unknown fields refused, a fraction refused for an integer, null refused) and pass check, when check is non-nil; if it does not, Get refuses naming the key, the value and its origin, and never moves on to a lower layer or to the default.

func InterviewList added in v0.13.0

func InterviewList(r Roots) (Value[string], error)

InterviewList resolves interview.list from the machine's ~/.abcd.noindex/config.json, else the bundled arrows. It claims the interview namespace, so a misspelt key is refused, and it is the machine's alone: how a person reads a list is theirs to say, so a repository's .abcd/config.json that sets it is refused naming the machine's file, as a value outside the two is, never passed over for the default. The machine's file setting interview.redrafts, the repository's key, is refused the same way, so a setting nothing would read never passes unannounced.

func InterviewRedrafts added in v0.16.1

func InterviewRedrafts(r Roots) (Value[int], error)

InterviewRedrafts resolves interview.redrafts from the repository's .abcd/config.json, else the bundled InterviewRedraftsDefault. It claims the interview namespace as InterviewList does, and it is the repository's alone: how hard its interviews hold an interviewer to the asking rules before showing what it wrote is the repository's to say, so the machine's file setting it is refused naming the repository's. A value that is not a whole number from 0 to InterviewRedraftsMax is refused naming the key, the value and the file, never passed over for the default.

Jump to

Keyboard shortcuts

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