patternsv2

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2026 License: MIT Imports: 15 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 patternsv2 implements experimental, bounded Pattern records only. It performs no persistence, device discovery, admission or execution.

Index

Constants

View Source
const (
	RecordContract  = patternidentity.RecordContract
	SnapshotKind    = "nb1-pattern-snapshot/experimental-v2"
	ExecutionDomain = patternidentity.ExecutionDomain
	SchemaVersion   = 2
	MaxBytes        = 1 << 20
	MaxRecords      = 128
	MaxDepth        = 32
)

Variables

View Source
var (
	ErrInvalid     = errors.New("invalid experimental pattern")
	ErrUnsupported = errors.New("unsupported experimental pattern verifier")
)
View Source
var ErrRevisionConflict = errors.New("experimental pattern candidate revision conflict")

ErrRevisionConflict means the author's expected_revision does not identify the newly compiled candidate. It is not a conflict with a stored record.

Functions

func CanonicalRecordJSON

func CanonicalRecordJSON(r Record) ([]byte, error)

CanonicalRecordJSON is the SHA payload only: no revision or domain prefix.

func EncodeRecord

func EncodeRecord(r Record) ([]byte, error)

EncodeRecord returns verified canonical wire bytes. It cannot publish an unknown recipe; Inspection.CanonicalJSON supplies its read-only export.

func EncodeSnapshot

func EncodeSnapshot(records []Record) ([]byte, error)

func ExecutionDigest

func ExecutionDigest(r Record) (string, error)

Types

type Candidate

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

Candidate is an immutable, verified authoring result. Its Record retains the author's high-level source alongside the frozen execution and revision. Accessors return independent mutable data; no store or executor is involved.

func PreviewDraft

func PreviewDraft(data []byte) (Candidate, error)

PreviewDraft strictly decodes raw authoring JSON {id,title,source}, then uses NewRecord and the existing pure preview functions. expected_revision and all other additional fields are rejected. Decode the original bytes here rather than unmarshaling them first: encoding/json can replace lone surrogates.

func (Candidate) ExecutionDigest

func (c Candidate) ExecutionDigest() string

func (Candidate) Preview

func (c Candidate) Preview() PreviewFacts

func (Candidate) Record

func (c Candidate) Record() Record

func (Candidate) Support

func (c Candidate) Support() Support

type Compiled

type Compiled struct {
	NormalizedAction json.RawMessage `json:"normalized_action"`
	RecipeID         string          `json:"recipe_id,omitempty"`
	Execution        Execution       `json:"execution"`
}

type Execution

type Execution struct {
	Kind         string                `json:"-"`
	Contract     string                `json:"-"`
	Program      *control.Program      `json:"-"`
	FrameProgram *control.FrameProgram `json:"-"`
}

Execution is a typed union. Exactly the matching Program/FrameProgram is populated; the wire shape always has one "program" field. It is data, not an execution capability, and even a verified record does not qualify hardware.

func (Execution) MarshalJSON

func (e Execution) MarshalJSON() ([]byte, error)

type Inspection

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

Inspection deliberately separates an integrity-checked, read-only document from a record accepted by a known source/recipe verifier. Private snapshots cannot be changed by mutating a returned Record or byte slice.

func InspectRecord

func InspectRecord(data []byte) (Inspection, error)

func (Inspection) CanonicalJSON

func (i Inspection) CanonicalJSON() []byte

func (Inspection) ExecutionDigest

func (i Inspection) ExecutionDigest() string

func (Inspection) Record

func (i Inspection) Record() Record

func (Inspection) Support

func (i Inspection) Support() Support

func (Inspection) VerifiedRecord

func (i Inspection) VerifiedRecord() (Record, error)

VerifiedRecord never treats an unknown recipe as executable/verified data.

type PreviewFacts

type PreviewFacts struct {
	Kind                 string   `json:"kind"`
	Contract             string   `json:"contract"`
	NominalDurationMS    int64    `json:"nominal_duration_ms"`
	TimingBasis          string   `json:"timing_basis"`
	RequiredCapabilities []string `json:"required_capabilities"`
	TotalSteps           *int     `json:"total_steps,omitempty"`
	TotalFrames          *int     `json:"total_frames,omitempty"`
	StoredTargetWrites   *int     `json:"stored_target_writes,omitempty"`
	PlannedTargetWrites  *int     `json:"planned_target_writes,omitempty"`
	CycleDurationMS      *int64   `json:"cycle_duration_ms,omitempty"`
	NominalInitialMS     *int64   `json:"nominal_initial_ms,omitempty"`
	NominalTailMS        *int64   `json:"nominal_tail_ms,omitempty"`
}

PreviewFacts contains nominal, pure compiler facts. The selected execution kind determines which optional fields exist, including meaningful zeroes. It does not establish device support, admission or observed wall time.

type Record

type Record struct {
	Contract string   `json:"record_contract"`
	ID       string   `json:"id"`
	Title    string   `json:"title"`
	Source   Source   `json:"source"`
	Compiled Compiled `json:"compiled"`
	Revision string   `json:"revision"`
}

func DecodeRecord

func DecodeRecord(data []byte) (Record, error)

DecodeRecord accepts only a fully verified record. InspectRecord is the explicitly read-only path for a structurally valid but unsupported recipe.

func DecodeSnapshot

func DecodeSnapshot(data []byte) ([]Record, error)

func NewRecord

func NewRecord(id, title string, source Source) (Record, error)

NewRecord freezes one known high-level source. There is no ID registry or replacement here; persistence and its create-only transaction remain absent.

func NormalizeRecord

func NormalizeRecord(r Record) (Record, error)

type SaveCandidate

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

SaveCandidate adds one canonical snapshot to a confirmed Candidate. It is only an input for a later create-only store transaction, not a saved record, overwrite authorization, execution ticket or device capability check.

func PrepareSave

func PrepareSave(data []byte) (SaveCandidate, error)

PrepareSave strictly decodes {id,title,source,expected_revision}. Confirmation binds the complete candidate, including the author's source notation. The returned snapshot uses the existing frozen Snapshot contract unchanged. No persistence, path lookup, device discovery or execution occurs.

func (SaveCandidate) Candidate

func (s SaveCandidate) Candidate() Candidate

func (SaveCandidate) SnapshotJSON

func (s SaveCandidate) SnapshotJSON() []byte

type SnapshotInspection

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

SnapshotInspection can carry unsupported records for explicit read-only backup. Strict DecodeSnapshot/EncodeSnapshot accept verified records only. It does not imply a store exists, or that any record can run on a device.

func InspectSnapshot

func InspectSnapshot(data []byte) (SnapshotInspection, error)

func (SnapshotInspection) CanonicalJSON

func (s SnapshotInspection) CanonicalJSON() []byte

func (SnapshotInspection) Records

func (s SnapshotInspection) Records() []Inspection

func (SnapshotInspection) VerifiedRecords

func (s SnapshotInspection) VerifiedRecords() ([]Record, error)

type Source

type Source struct {
	Kind     string          `json:"kind"`
	Contract string          `json:"contract"`
	Action   json.RawMessage `json:"action"`
}

Source retains the author's JSON meaning, including color notation and omitted defaults. Action is canonical JSON, not the original file bytes.

type Support

type Support struct {
	Verified bool   `json:"verified"`
	Reason   string `json:"reason"`
}

Support describes semantic verification only. Verified does not mean an executor, device or persistence layer is available.

Jump to

Keyboard shortcuts

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