nano

package
v0.1.0-alpha Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Overview

Package nano implements AntiFlock's deterministic, I/O-free conformance runtime for Nano v0.1. It follows DBarr3/Nano PR #1 without copying its Python implementation. Programs can only produce typed intents; this package has no filesystem, process, network, clock, randomness, or host mutation capability.

Index

Constants

View Source
const (
	IRVersion      = "0.1.0"
	UpstreamCommit = "40f697ba9020a4d4fee985406779c0d90ea2d6f4"
)

Variables

View Source
var (
	ErrLimitExceeded    = errors.New("nano resource limit exceeded")
	ErrAdmissionDenied  = errors.New("nano program is outside the AntiFlock intent profile")
	ErrInvalidFrame     = errors.New("nano evaluation frame is invalid")
	ErrInstructionLimit = errors.New("nano instruction budget exhausted")
)
View Source
var DefaultLimits = Limits{
	MaxSourceBytes: 64 << 10, MaxTokens: 4096, MaxAgents: 16,
	MaxConditions: 64, MaxIntents: 16, MaxSignals: 128,
	MaxTimestamps: 1024, MaxInstructions: 8192, MaxOutputs: 128,
}

Functions

func AdmitWatchdog

func AdmitWatchdog(program Program) error

func BindingDigest

func BindingDigest(bindingID BindingID) (string, error)

func Evaluate

func Evaluate(program Program, frame Frame, cursor Cursor, limits Limits) (EvaluationResult, Cursor, error)

Types

type AdmissionRequest

type AdmissionRequest struct {
	NodeID      string
	Source      string
	BindingID   BindingID
	OperationID string
	ActorID     string
}

type BindingID

type BindingID string
const (
	BindingScramblerSimulation BindingID = "scrambler-simulation-v1"
	BindingFixtureShodan       BindingID = "fixture-shodan-query-v1"
	BindingFixtureBroker       BindingID = "fixture-broker-query-v1"
	BindingFixturePaste        BindingID = "fixture-paste-query-v1"
	BindingCountermeasurePlan  BindingID = "countermeasure-plan-v1"
)

type Condition

type Condition struct {
	Signal   string  `json:"signal"`
	Operator string  `json:"operator"`
	Value    float64 `json:"value"`
}

type Cursor

type Cursor struct {
	Initialized bool  `json:"initialized"`
	NextDueUnix int64 `json:"nextDueUnix"`
}

type CursorStore

type CursorStore interface {
	Load(ctx context.Context, programDigest, nodeID string) (Cursor, error)
	CompareAndSwap(ctx context.Context, programDigest, nodeID string, previous, next Cursor) (bool, error)
}

CursorStore persists a per-program, per-node schedule cursor. Production runners must supply durable storage before handling real findings.

type EmittedIntent

type EmittedIntent struct {
	Action    string `json:"action"`
	Timestamp int64  `json:"timestamp"`
}

type EvaluationResult

type EvaluationResult struct {
	Intents      []EmittedIntent `json:"intents"`
	Trace        []TraceEntry    `json:"trace"`
	Instructions int             `json:"instructions"`
}

type FindingContext

type FindingContext struct {
	FindingID    string
	NodeID       string
	ReasonCode   string
	Confidence   float64
	ObservedUnix int64
}

type FindingRunResult

type FindingRunResult struct {
	FindingID string    `json:"findingId"`
	Result    RunResult `json:"result"`
}

FindingRunResult binds a proposal-only result to the Core finding that supplied the host-owned input. It contains neither raw evidence nor a caller-selected signal.

type Frame

type Frame struct {
	Timestamps []int64
	Signals    map[string][]float64
}

func FrameForFinding

func FrameForFinding(finding FindingContext) (Frame, string, error)

type Intent

type Intent struct {
	Action     string   `json:"action"`
	Asset      string   `json:"asset,omitempty"`
	Confidence *float64 `json:"confidence,omitempty"`
}

type Limits

type Limits struct {
	MaxSourceBytes  int
	MaxTokens       int
	MaxAgents       int
	MaxConditions   int
	MaxIntents      int
	MaxSignals      int
	MaxTimestamps   int
	MaxInstructions int
	MaxOutputs      int
}

type MemoryCursorStore

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

MemoryCursorStore is for deterministic tests and demos. It is not durable.

func NewMemoryCursorStore

func NewMemoryCursorStore() *MemoryCursorStore

func (*MemoryCursorStore) CompareAndSwap

func (store *MemoryCursorStore) CompareAndSwap(ctx context.Context, programDigest, nodeID string, previous, next Cursor) (bool, error)

func (*MemoryCursorStore) Load

func (store *MemoryCursorStore) Load(ctx context.Context, programDigest, nodeID string) (Cursor, error)

type OpenFindingRunResult

type OpenFindingRunResult struct {
	ProgramID      string             `json:"programId"`
	NodeID         string             `json:"nodeId"`
	EvaluatedCount int                `json:"evaluatedCount"`
	SkippedStale   int                `json:"skippedStale"`
	Results        []FindingRunResult `json:"results"`
}

OpenFindingRunResult is a bounded, deterministic Core-owned watchdog pass. It is operator-invoked and proposal-only; it neither authorizes nor executes a proposed action.

type Program

type Program struct {
	Name       string
	Schedule   *Schedule
	Conditions []Condition
	Intents    []Intent
	Agents     []string
}

func Compile

func Compile(source string, limits Limits) (Program, error)

func (Program) CanonicalJSON

func (program Program) CanonicalJSON() ([]byte, error)

func (Program) Digest

func (program Program) Digest() (string, error)

type Registry

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

Registry admits immutable Nano source into the constrained watchdog profile. It has no provider, process, network, or action-execution capability.

func NewRegistry

func NewRegistry(database *storage.DB, auditService *audit.Service, clock func() time.Time) (*Registry, error)

func (*Registry) Admit

func (*Registry) List

func (registry *Registry) List(ctx context.Context, nodeID string) ([]storage.NanoWatchdogProgramRecord, error)

func (*Registry) RunFinding

func (registry *Registry) RunFinding(ctx context.Context, programID string, finding FindingContext) (RunResult, error)

func (*Registry) RunOpenFindings

func (registry *Registry) RunOpenFindings(ctx context.Context, programID string, findings []FindingContext) (OpenFindingRunResult, error)

RunOpenFindings evaluates an admitted program against already-created Core findings. Callers cannot inject a signal: the server builds FindingContext values from the current OPEN finding projection. Inputs are sorted and capped before cursor advancement so one request has deterministic work bounds.

type RunResult

type RunResult struct {
	ProgramDigest string                 `json:"programDigest"`
	InputDigest   string                 `json:"inputDigest"`
	Evaluation    EvaluationResult       `json:"evaluation"`
	Proposals     []SecureActionProposal `json:"proposals"`
}

RunResult is the stable, proposal-only watchdog response. It never signals authorization or execution; a separate operator-approved action flow remains required.

type Runner

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

Runner evaluates one admitted program. It cannot fetch data, contact a provider, mutate a host, or submit a proposal to the action gate.

func NewRunner

func NewRunner(config RunnerConfig) (*Runner, error)

func (*Runner) RunFinding

func (runner *Runner) RunFinding(ctx context.Context, finding FindingContext) (RunResult, error)

RunFinding saves the cursor before returning proposals so a failed persist never exposes a proposal that can refire after a process restart.

type RunnerConfig

type RunnerConfig struct {
	Program     Program
	BindingID   BindingID
	NodeID      string
	ProposalTTL time.Duration
	Store       CursorStore
	Clock       func() time.Time
}

type Schedule

type Schedule struct {
	Interval string `json:"interval"`
	Seconds  int64  `json:"-"`
}

type SecureActionProposal

type SecureActionProposal struct {
	ID            string    `json:"id"`
	ApplicationID string    `json:"applicationId"`
	NodeID        string    `json:"nodeId"`
	ActionType    string    `json:"actionType"`
	Destinations  []string  `json:"destinations"`
	DataClass     string    `json:"dataClass"`
	Sensitivity   string    `json:"sensitivity"`
	Deadline      string    `json:"deadline"`
	OperationID   string    `json:"operationId"`
	BindingID     BindingID `json:"bindingId"`
	ProgramDigest string    `json:"programDigest"`
	InputDigest   string    `json:"inputDigest"`
}

SecureActionProposal is the only outward value Nano can produce. It mirrors the existing gate request but carries no payload and performs no action.

func BuildProposals

func BuildProposals(
	result EvaluationResult,
	bindingID BindingID,
	programDigest, inputDigest, nodeID, deadline string,
) ([]SecureActionProposal, error)

type StorageCursorStore

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

StorageCursorStore adapts Core's SQLite store to the watchdog runner. The runner can therefore survive restarts without admitting mutable programs or persisting raw findings.

func NewStorageCursorStore

func NewStorageCursorStore(database *storage.DB, clock func() time.Time) (*StorageCursorStore, error)

func (*StorageCursorStore) CompareAndSwap

func (store *StorageCursorStore) CompareAndSwap(ctx context.Context, programDigest, nodeID string, previous, next Cursor) (bool, error)

func (*StorageCursorStore) Load

func (store *StorageCursorStore) Load(ctx context.Context, programDigest, nodeID string) (Cursor, error)

type SyntaxError

type SyntaxError struct {
	Message string
	Line    int
	Column  int
}

func (*SyntaxError) Error

func (err *SyntaxError) Error() string

type TraceEntry

type TraceEntry struct {
	Event     string `json:"event"`
	Timestamp int64  `json:"timestamp"`
	Detail    string `json:"detail"`
}

Jump to

Keyboard shortcuts

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