interleavedstate

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package interleavedstate holds pure, serializable value types shared by routing, continuity, and runtime for interleaved thinking.

The package must stay free of runtime or memo-processing dependencies so it can be imported by any core package without introducing cycles. Only the standard library is used.

Package interleavedstate Interleaved-thinking state tracking for multi-turn reasoning.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalStateText

func MarshalStateText(state State) (string, error)

MarshalStateText serializes state for compact durable storage. Empty state is encoded as an empty string so old rows and non-thinker routes stay cheap.

Types

type CycleEntry

type CycleEntry struct {
	Key  string `json:"key"`
	Role Role   `json:"role"`
}

CycleEntry is one position in a thinker-aware weighted cycle. Key identifies the branch within its selector; Role records whether it is the thinker branch.

type CycleState

type CycleState struct {
	SelectorKey string       `json:"selector_key,omitempty"`
	Sequence    []CycleEntry `json:"sequence,omitempty"`
	NextIndex   int          `json:"next_index"`
}

CycleState is the selector-scoped cursor for thinker-aware weighted cycles. An empty (zero-value) state means no cycle has been established yet.

func (CycleState) Equal

func (c CycleState) Equal(other CycleState) bool

Equal reports whether two cycle states have identical selector, sequence, and cursor. It is invariant under nil-vs-empty sequence normalization.

func (CycleState) IsEmpty

func (c CycleState) IsEmpty() bool

IsEmpty reports whether the cycle state has no established sequence.

func (CycleState) MarshalJSON

func (c CycleState) MarshalJSON() ([]byte, error)

MarshalJSON serializes CycleState with nil sequence normalized to empty so round-trip equality holds for zero-value inputs.

func (CycleState) MatchesSelector

func (c CycleState) MatchesSelector(selectorKey string) bool

MatchesSelector reports whether the stored cycle is fresh for the given selector key. An empty state is considered fresh for any selector (callers treat missing state as a new session for cycle purposes).

func (CycleState) Validate

func (c CycleState) Validate() error

Validate checks that a non-empty cycle state has an in-bounds cursor. An empty state is valid.

type Role

type Role string

Role labels a cycle entry or routing candidate as thinker, executor, or none.

const (
	// RoleNone is the zero value for unannotated entries and candidates.
	RoleNone Role = ""
	// RoleThinker marks a weighted branch that produces a planning memo.
	RoleThinker Role = "thinker"
	// RoleExecutor marks a branch that consumes a memo and produces client output.
	RoleExecutor Role = "executor"
)

type State

type State struct {
	Cycle CycleState `json:"cycle"`
}

State bundles the cycle cursor for one A-leg required by routing and continuity. Memo payload and reference semantics are owned by the interleavedthinking feature, not by core interleavedstate.

func UnmarshalStateText

func UnmarshalStateText(encoded string) (State, error)

UnmarshalStateText decodes state produced by MarshalStateText. An empty string is the zero state for backward-compatible durable rows.

func (State) Equal

func (s State) Equal(other State) bool

Equal reports whether two states have equal cycle parts.

func (State) IsEmpty

func (s State) IsEmpty() bool

IsEmpty reports whether the state carries no established cycle sequence.

func (State) Validate

func (s State) Validate() error

Validate validates the cycle portion of the state.

Jump to

Keyboard shortcuts

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