contracts

package
v0.3.1 Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: Apache-2.0 Imports: 7 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

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnabledRuleIDs added in v0.3.1

func EnabledRuleIDs() []string

EnabledRuleIDs returns the deterministic contract evaluator rule set.

func Float64

func Float64(v float64) *float64

Float64 makes pointer-valued numeric fields readable in struct literals. Go does not allow taking the address of a literal such as &3.3.

func UnknownPowerCriticalRefs added in v0.3.1

func UnknownPowerCriticalRefs(design *ir.DesignIR, contractIR *ContractIR) []string

Types

type AppliedRequirement added in v0.3.1

type AppliedRequirement struct {
	Requirement
	ComponentRef string     `json:"component_ref"`
	ComponentMPN string     `json:"component_mpn,omitempty"`
	Source       string     `json:"source"`
	Provenance   Provenance `json:"provenance"`
}

AppliedRequirement is a Requirement bound to a concrete DesignIR component.

type BuiltinPartsSource added in v0.3.1

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

BuiltinPartsSource exposes the curated v0.3.1 built-in contracts as one ContractSource. Built-in contracts are intentionally minimal. This is NOT a general-purpose parts database.

func NewBuiltinPartsSource added in v0.3.1

func NewBuiltinPartsSource() BuiltinPartsSource

func (BuiltinPartsSource) Enrich added in v0.3.1

func (s BuiltinPartsSource) Enrich(design *ir.DesignIR) (*ContractIR, error)

func (BuiltinPartsSource) Name added in v0.3.1

func (s BuiltinPartsSource) Name() string

type ComponentContract

type ComponentContract struct {
	Ref        string                 `json:"ref"`
	MPN        string                 `json:"mpn,omitempty"`
	Pins       map[string]PinContract `json:"pins,omitempty"`
	VoltageMax *float64               `json:"voltage_max,omitempty"`
	Source     string                 `json:"source,omitempty"`
}

ComponentContract stores component-level limits and per-pin contracts.

type ContractIR

type ContractIR struct {
	Components          map[string]ComponentContract `json:"components"`
	Nets                map[string]NetContract       `json:"nets"`
	PartMatches         []PartMatch                  `json:"part_matches,omitempty"`
	AppliedRequirements []AppliedRequirement         `json:"applied_requirements,omitempty"`
	MissingContractData []MissingContractData        `json:"missing_contract_data,omitempty"`
}

ContractIR is the complete contract view attached to a DesignIR. It can be assembled from several independent sources before rules run.

func NewContractIR

func NewContractIR() *ContractIR

NewContractIR creates an initialized contract container.

func (*ContractIR) EnsureComponent

func (c *ContractIR) EnsureComponent(ref string) ComponentContract

EnsureComponent returns a mutable component contract entry, creating it when needed. Call PutComponent after changing the returned value.

func (*ContractIR) Merge

func (c *ContractIR) Merge(other *ContractIR)

Merge combines another ContractIR into this one. Existing data wins so source order can express precedence without losing later missing-data warnings.

func (*ContractIR) Net

func (c *ContractIR) Net(net string) (NetContract, bool)

Net looks up a contract for a normalized DesignIR net name.

func (*ContractIR) Pin

func (c *ContractIR) Pin(ref string, pin string) (PinContract, bool)

Pin looks up a pin contract by component reference and pin name/number.

func (*ContractIR) PutAppliedRequirement added in v0.3.1

func (c *ContractIR) PutAppliedRequirement(req AppliedRequirement)

PutAppliedRequirement records a concrete requirement after source matching.

func (*ContractIR) PutComponent

func (c *ContractIR) PutComponent(component ComponentContract)

PutComponent writes a component contract back into the ContractIR.

func (*ContractIR) PutNet

func (c *ContractIR) PutNet(net string, contract NetContract)

PutNet attaches or merges a net contract.

func (*ContractIR) PutPin

func (c *ContractIR) PutPin(ref string, pin string, contract PinContract)

PutPin attaches or merges a pin contract for ref/pin.

type ContractScope added in v0.3.1

type ContractScope struct {
	ComponentRef string   `json:"component_ref,omitempty"`
	MPN          string   `json:"mpn,omitempty"`
	Pins         []string `json:"pins,omitempty"`
	Net          string   `json:"net,omitempty"`
	Role         PinRole  `json:"role,omitempty"`
}

ContractScope says where a requirement applies after a part is matched.

type ContractSource added in v0.3.1

type ContractSource interface {
	Name() string
	Enrich(design *ir.DesignIR) (*ContractIR, error)
}

ContractSource is one independent source of deterministic contract data. Source order expresses precedence; earlier sources win during ContractIR.Merge.

type ContractType added in v0.3.1

type ContractType string

ContractType identifies the deterministic built-in contract rule family.

const (
	ContractSupplyAbsMax           ContractType = "supply_abs_max"
	ContractSupplyRecommendedRange ContractType = "supply_recommended_range"
	ContractGPIOAbsMax             ContractType = "gpio_abs_max"
	ContractMotorDriverVMRange     ContractType = "motor_driver_vm_range"
	ContractRegulatorOutputCurrent ContractType = "regulator_output_current"
)

type CoverageSummary

type CoverageSummary struct {
	ComponentsTotal          int      `json:"components_total"`
	ComponentsWithContracts  int      `json:"components_with_contracts"`
	PinsTotal                int      `json:"pins_total"`
	PinsWithContracts        int      `json:"pins_with_contracts"`
	NetsTotal                int      `json:"nets_total"`
	NetsWithContracts        int      `json:"nets_with_contracts"`
	PartsMatched             int      `json:"parts_matched"`
	ContractsApplied         int      `json:"contracts_applied"`
	CoveragePercentage       float64  `json:"coverage_percentage"`
	UnknownPowerCriticalRefs []string `json:"unknown_power_critical_refs,omitempty"`
	EnabledContractRules     []string `json:"enabled_contract_rules,omitempty"`
	MissingWarnings          []string `json:"missing_warnings,omitempty"`
}

CoverageSummary is report-facing coverage data for contract completeness.

func SummarizeCoverage

func SummarizeCoverage(design *ir.DesignIR, contractIR *ContractIR) CoverageSummary

SummarizeCoverage compares DesignIR connectivity with available contracts.

type Direction

type Direction string

Direction captures signal flow at the contract level.

const (
	DirectionInput         Direction = "input"
	DirectionOutput        Direction = "output"
	DirectionBidirectional Direction = "bidirectional"
	DirectionPassive       Direction = "passive"
	DirectionUnknown       Direction = "unknown"
)

type FieldContractSource added in v0.3.1

type FieldContractSource struct{}

FieldContractSource adapts explicit schematic/BOM fields into contracts. Supported fields are intentionally namespaced or plain deterministic keys, never scraped free text.

func (FieldContractSource) Enrich added in v0.3.1

func (s FieldContractSource) Enrich(design *ir.DesignIR) (*ContractIR, error)

func (FieldContractSource) Name added in v0.3.1

func (FieldContractSource) Name() string

type Finding added in v0.3.1

type Finding struct {
	RuleID       string     `json:"rule_id"`
	Severity     string     `json:"severity"`
	Message      string     `json:"message"`
	ComponentRef string     `json:"component_ref,omitempty"`
	Net          string     `json:"net,omitempty"`
	Pin          string     `json:"pin,omitempty"`
	Source       string     `json:"source,omitempty"`
	Provenance   Provenance `json:"provenance,omitempty"`
	Fix          string     `json:"fix,omitempty"`
}

Finding is a contract-evaluator finding before it is adapted into report JSON.

func Evaluate added in v0.3.1

func Evaluate(design *ir.DesignIR, contractIR *ContractIR) []Finding

Evaluate runs deterministic contract requirements that are not represented by the older generic ContractIR rules.

type MatchResult added in v0.3.1

type MatchResult struct {
	Matched    bool
	Ambiguous  bool
	Query      string
	Kind       string
	Contract   SystemContract
	Candidates []string
}

MatchResult describes a deterministic part-to-contract match. Ambiguous results deliberately have Matched=false so callers cannot accidentally apply a contract guessed from more than one candidate.

func MatchPart added in v0.3.1

func MatchPart(part ir.Part, catalog []SystemContract) MatchResult

MatchPart matches a DesignIR part to a SystemContract by exact MPN or alias. It rejects ambiguity and does not do fuzzy substring search.

type MissingContractData

type MissingContractData struct {
	Kind    string `json:"kind"`
	Ref     string `json:"ref,omitempty"`
	Pin     string `json:"pin,omitempty"`
	Net     string `json:"net,omitempty"`
	Message string `json:"message"`
}

MissingContractData records known analysis gaps. These become warnings so the report is transparent about what was not checked.

type NetContract

type NetContract struct {
	Net            string   `json:"net"`
	VoltageMin     *float64 `json:"voltage_min,omitempty"`
	VoltageNominal *float64 `json:"voltage_nominal,omitempty"`
	VoltageMax     *float64 `json:"voltage_max,omitempty"`
	LogicFamily    string   `json:"logic_family,omitempty"`
	Source         string   `json:"source,omitempty"`
}

NetContract stores facts that apply to a whole net, such as inferred or explicitly configured rail voltage.

type PartMatch added in v0.3.1

type PartMatch struct {
	Ref         string     `json:"ref"`
	MPN         string     `json:"mpn"`
	ContractMPN string     `json:"contract_mpn"`
	Kind        string     `json:"kind"`
	Source      string     `json:"source"`
	Provenance  Provenance `json:"provenance"`
}

PartMatch records a deterministic match between a DesignIR part and a SystemContract.

type PinContract

type PinContract struct {
	Ref            string    `json:"ref,omitempty"`
	Pin            string    `json:"pin,omitempty"`
	Role           PinRole   `json:"role"`
	VoltageMin     *float64  `json:"voltage_min,omitempty"`
	VoltageNominal *float64  `json:"voltage_nominal,omitempty"`
	VoltageMax     *float64  `json:"voltage_max,omitempty"`
	CurrentMax     *float64  `json:"current_max,omitempty"`
	LogicFamily    string    `json:"logic_family,omitempty"`
	Direction      Direction `json:"direction"`
	OpenDrain      *bool     `json:"open_drain,omitempty"`
	Source         string    `json:"source,omitempty"`
}

PinContract is the rule-facing electrical contract for a single component pin.

type PinRole

type PinRole string

PinRole describes what a pin electrically does in a design-neutral way. Rules use these roles instead of package-, symbol-, or EDA-specific names.

const (
	RolePowerIn      PinRole = "power_in"
	RolePowerOut     PinRole = "power_out"
	RoleRegulatorOut PinRole = "regulator_out"
	RoleSource       PinRole = "source"
	RoleGPIO         PinRole = "gpio"
	RoleI2CSDA       PinRole = "i2c_sda"
	RoleI2CSCL       PinRole = "i2c_scl"
	RoleSPI          PinRole = "spi"
	RoleUART         PinRole = "uart"
	RoleMotorOut     PinRole = "motor_out"
	RoleGround       PinRole = "ground"
	RoleUnknown      PinRole = "unknown"
)

type Provenance added in v0.3.1

type Provenance struct {
	Source   string `json:"source"`
	SourceID string `json:"source_id,omitempty"`
	Detail   string `json:"detail,omitempty"`
}

Provenance records where a deterministic contract or finding came from.

type Requirement added in v0.3.1

type Requirement struct {
	Type       ContractType  `json:"type"`
	Scope      ContractScope `json:"scope"`
	MinVoltage *float64      `json:"min_voltage,omitempty"`
	MaxVoltage *float64      `json:"max_voltage,omitempty"`
	MaxCurrent *float64      `json:"max_current,omitempty"`
	Severity   string        `json:"severity,omitempty"`
	Message    string        `json:"message,omitempty"`
	Fix        string        `json:"fix,omitempty"`
	Provenance Provenance    `json:"provenance,omitempty"`
}

Requirement is the normalized rule input for one electrical constraint.

type SystemContract added in v0.3.1

type SystemContract struct {
	MPN          string        `json:"mpn"`
	Manufacturer string        `json:"manufacturer,omitempty"`
	Aliases      []string      `json:"aliases,omitempty"`
	Description  string        `json:"description,omitempty"`
	Requirements []Requirement `json:"requirements"`
	GroundPins   []string      `json:"-"`
	Provenance   Provenance    `json:"provenance"`
}

SystemContract is a deterministic component contract. It is intentionally small: it describes known electrical requirements for one concrete MPN or alias set, not a generic searchable parts database.

func BuiltinContracts added in v0.3.1

func BuiltinContracts() []SystemContract

BuiltinContracts returns the small curated v0.3.1 catalog. Built-in contracts are intentionally minimal. This is NOT a general-purpose parts database.

Jump to

Keyboard shortcuts

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