Help us shape the future of Go! Take the 2026 Go Developer Survey

contract

package
v1.1.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	SyncVerbPush   = "sync.push"
	SyncVerbPull   = "sync.pull"
	SyncVerbStatus = "sync.status"
)

The three Remote Workspace sync wire verbs (sync-abi-v1 §1). They live in contract because the ABI names them: the channel binding layer and the standalone hub (syncserver/mnemon-hub) must agree on the strings without either importing the other. Deliberately untyped so channel can alias them into its Verb space unchanged.

View Source
const (
	ConflictReject            = "reject"
	ConflictRebase            = "rebase"
	ConflictAutoMergeDisjoint = "auto_merge_disjoint"
	ConflictDeferToHuman      = "defer_to_human"

	IsolationWriteCAS          = "write_cas"
	IsolationProjectionReadSet = "projection_read_set"

	AuthzStrict = "strict" // enforce rules; violation -> Rejected. The only IMPLEMENTED authz mode.
	// Reserved — NOT in AuthzCatalog until implemented with real, distinct teeth (mirrors `serializable`).
	// The kernel currently enforces rules UNCONDITIONALLY (= strict, fail-closed), so advertising these as
	// selectable would promise behavior it cannot deliver — and selecting dry_run would still commit.
	// Deferred semantics if/when built: permissive & audit_only would both be "allow-despite-violation"
	// (byte-identical — the anti-pattern that dropped `serializable`); dry_run = validate-but-never-commit.
	AuthzPermissive = "permissive"
	AuthzAuditOnly  = "audit_only"
	AuthzDryRun     = "dry_run"
)
View Source
const SyncImportActor = ActorID("sync@local")

SyncImportActor is the well-known principal under which pulled remote commits re-enter Event Intake. The runtime uses it to skip re-recording sync commits for sync-imported decisions; the app sync glue drives the import runtime under it.

Variables

View Source
var (
	ConflictCatalog  = map[string]bool{ConflictReject: true, ConflictRebase: true, ConflictAutoMergeDisjoint: true, ConflictDeferToHuman: true}
	IsolationCatalog = map[string]bool{IsolationWriteCAS: true, IsolationProjectionReadSet: true}
	AuthzCatalog     = map[string]bool{AuthzStrict: true} // only strict is implemented; the rest are reserved (see consts above)
)

Catalog membership — the define≠select guard (Invariant #12) checks against these.

View Source
var GovernanceKinds = map[ResourceKind]bool{"lease": true, "budget": true, "receipt": true, "coordination": true}

GovernanceKinds are the kernel-internal control-plane kinds (D3): their writes are kernel-produced, never proposed by a capability. They are the compiled core a capability spec may NEVER declare (capability.FromSpec G8 reservation) and that the assembly-time SchemaGuard always carries. User kinds, by contrast, are declared by capability specs and registered at assembly time — so the live kernel's known-kind set is GovernanceKinds ∪ the enabled capabilities' kinds, not this compiled KindCatalog (which now only pins the kernel-test lockstep and documents the platform kinds).

View Source
var KindCatalog = map[ResourceKind]bool{"lease": true, "budget": true, "receipt": true, "coordination": true}

Functions

This section is empty.

Types

type ActorID

type ActorID string

ActorID is an IDENTITY, not a role enum (Invariant #11/#15).

type ActorKind

type ActorKind string

ActorKind classifies a channel principal by role. It is NOT a privilege path: the channel is the same for every principal; the role differs by binding, never by a privileged code path (D6). HostAgent pushes host observations; ControlAgent is an operator/control client; ReplicaAgent is the background Remote Workspace sync actor.

const (
	KindHostAgent    ActorKind = "host-agent"
	KindControlAgent ActorKind = "control-agent"
	KindReplicaAgent ActorKind = "replica-agent"
)

type BudgetTier

type BudgetTier string

BudgetTier is the closed set of context-budget tiers (P4). It SELECTS a local rendering shape from a fixed catalog — it never DEFINES behavior (A3/define≠select). The tier is applied where the local replica derives its mirror from already-pulled commits; the hub is never tier-aware (B1/B2 no remote reducer). Tiers, smallest context first:

  • BudgetDigestOnly: derive only a digest form (summary/count), not the full item list.
  • BudgetWarm: derive the most-recent K items (ordered by local import seq — replica-deterministic).
  • BudgetHot: derive the full item set.
const (
	BudgetHot        BudgetTier = "hot"
	BudgetWarm       BudgetTier = "warm"
	BudgetDigestOnly BudgetTier = "digest-only"
)

func ResolveBudgetTier

func ResolveBudgetTier(t BudgetTier) (BudgetTier, error)

ResolveBudgetTier normalizes a declared tier: empty resolves to hot (migration-safe full delivery), a catalogued tier passes through, and any other value is rejected (fail-loud, never silently widened or narrowed). This is the ONE place the empty=hot default and the closed-set guard live.

type ChannelStatus

type ChannelStatus struct {
	Principal     ActorID   `json:"principal"`
	Digest        string    `json:"digest"`
	Resources     int       `json:"resources"`
	ActorKind     ActorKind `json:"actor_kind,omitempty"`
	StoreRef      string    `json:"store_ref"`
	Mode          string    `json:"mode"`
	SyncPending   int       `json:"sync_pending"`
	SyncSynced    int       `json:"sync_synced"`
	SyncConflicts int       `json:"sync_conflicts"`
}

ChannelStatus is the principal's channel status surface (digest + scope counts + sync state).

type Conflict

type Conflict struct {
	Ref             ResourceRef
	ExpectedVersion Version
	ActualVersion   Version
	Kind            ConflictKind
}

type ConflictKind

type ConflictKind string
const (
	WriteWrite ConflictKind = "write_write"
	ReadStale  ConflictKind = "read_stale"
)

type Decision

type Decision struct {
	DecisionID    string
	OpID          string
	IngestSeq     int64
	Actor         ActorID
	CorrelationID string // carries the triggering event's correlation; the durable escalation key (Invariant #10)
	Status        DecisionStatus
	Reason        string
	Conflicts     []Conflict
	NextAction    string // "" (terminal) | "rebase" | "human_review"
	AppliedAt     string // RFC3339; set iff Accepted
	NewVersions   []ResourceVersion
	NewResources  []ResourceSnapshot
}

type DecisionStatus

type DecisionStatus string

---- decisions ----

const (
	Accepted DecisionStatus = "accepted"
	Rejected DecisionStatus = "rejected"
	Deferred DecisionStatus = "deferred"
)

type Diagnostic

type Diagnostic struct {
	Stage  string
	Reason string
	Ref    string
}

Diagnostic is the durable "why" of a reject/defer (S7: no silent drop). It is emitted as a "*.diagnostic" event so every rejection class leaves an auditable trail.

type Event

type Event struct {
	SchemaVersion int               `json:"schema_version"`
	ID            string            `json:"id"`
	IngestSeq     int64             `json:"ingest_seq"` // = events.rowid; the ONLY ordering key (Invariant #9)
	TS            string            `json:"ts"`         // provenance only; NEVER orders
	Type          string            `json:"type"`
	Actor         ActorID           `json:"actor"`
	ResourceRefs  []ResourceRef     `json:"resource_refs"`
	BasedOn       []ResourceVersion `json:"based_on"`       // read-set (Invariant #6)
	ProjectionRef string            `json:"projection_ref"` // provenance of the projection acted on
	ContextDigest string            `json:"context_digest"` // provenance; P1 may promote to a validation anchor
	CorrelationID string            `json:"correlation_id"`
	CausedBy      string            `json:"caused_by,omitempty"`
	Payload       map[string]any    `json:"payload"`
}

---- events ----

type KernelOp

type KernelOp struct {
	OpID          string
	Actor         ActorID
	Writes        []ResourceWrite
	ReadSet       []ResourceVersion
	IngestSeq     int64
	CorrelationID string // trusted envelope field; the durable key for liveness escalation (Invariant #10)
}

KernelOp is ALL-OR-NOTHING (Invariant #5). ReadSet = versions the proposer READ (Invariant #6). IngestSeq is the triggering event's durable seq (events.rowid), stamped by the reconciler from a TRUSTED source; 0 for a direct (non-event) Apply. It is the event<->decision audit link and the basis for the reconciler's durable cursor.

type LocalCommit

type LocalCommit struct {
	OriginReplicaID string
	LocalDecisionID string
	LocalIngestSeq  int64
	Actor           ActorID
	CorrelationID   string
	ResourceRef     ResourceRef
	ResourceVersion Version
	FieldsDigest    string
	Fields          map[string]any
	DecidedAt       string
	Status          string
}

LocalCommit is the append-only local sync unit materialized from an accepted local decision. It is durable local state; push/pull transports may serialize it, but Agent Integration never handles it directly.

type Modes

type Modes struct{ Conflict, Isolation, Authz string }

---- modes (the catalog NAMES live here — the standard advertises them) ----

func DefaultModes

func DefaultModes() Modes

KindCatalog documents the platform's compiled kinds and pins the kernel-test lockstep against kernel.DefaultSchemaGuard. The define≠select guard at RUNTIME is the kernel SchemaGuard itself (an unknown kind has no required fields, so SchemaGuard.Validate fails closed on it); since PD2 the live guard is the assembly-time set — GovernanceKinds ∪ the enabled capabilities' declared kinds — so a USER kind need not appear here to be admitted (a declared external kind registers at assembly). This map stays the compiled-default reference until memory/skill graduate (PD5). Invariant: keys(kernel.DefaultSchemaGuard().Required) == KindCatalog (enforced by a kernel test). lease/budget/receipt are GOVERNANCE resource kinds — first-class versioned resources (D3) whose per-resource Version is the fence / CAS counter; receipt is the durable record of an external effect. Their governed writes are kernel-produced control-plane state, kept registered for compatibility of existing logs and external-package reservation checks. coordination is the host-lifecycle teamwork-topology kind (P2.2 route 3/3): an approved coordination op is recorded as a governed coordination resource so the mutation flows through the kernel single-writer before the host emits its mirror topology events. DefaultModes is the ONE canonical mode set the platform runs under when nothing selects otherwise: the live server's zero-config default AND replay's reconciliation policy reference THIS — a divergence between the two silently breaks I6 (replay under different conflict semantics can accept what live rejected; exactly the historical replay-rebase defect).

type ObservationEnvelope

type ObservationEnvelope struct {
	Source     ActorID
	ExternalID string
	Event      Event
}

ObservationEnvelope is what an edge submits to the control server. Source is the AUTHENTICATED principal (the server overwrites Event.Actor from it — never the client payload, D7/S9); ExternalID is the edge's idempotency key for exactly-once ingest (S1: a retried (Source,ExternalID) returns the original seq).

type OpKind

type OpKind string

---- ops ----

const (
	OpCreate OpKind = "create"
	OpUpdate OpKind = "update"
)

type ProposedEvent

type ProposedEvent struct {
	Type    string
	Payload map[string]any
}

---- callback intent ----

type ReplicaGrant

type ReplicaGrant struct {
	Principal ActorID
	Token     string
	Scopes    []ResourceRef
}

ReplicaGrant is the replica-credential scope record both hub forms share (sync-abi-v1 §2 dual-form rule): a co-hosted hub derives it from a replica-agent channel binding entry; mnemon-hub derives it from a replicas.json entry. Same fields, same semantics. Token is the optional bearer credential (resolved from credential_ref); it is empty when the transport authenticates another way (e.g. the co-hosted hub's binding authenticator already resolved the principal).

type ResourceID

type ResourceID string

type ResourceKind

type ResourceKind string // "memory", "goal", "skill"

---- resources ----

type ResourceRef

type ResourceRef struct {
	Kind ResourceKind
	ID   ResourceID
}

func ClampRefs

func ClampRefs(principal ActorID, scope, requested []ResourceRef) ([]ResourceRef, error)

ClampRefs clamps a requested ref set to a principal's granted scope — the team-scale authorization ceiling, implemented ONCE for pull / sync / status (hand-rolled copies had already diverged on empty-scope handling). channel.ChannelBinding.ClampRefs and the syncserver hub both delegate here. Empty requested defaults to the full scope; any explicit ref outside the scope is an error; an EMPTY scope denies every explicit ref (fail closed). The ingest path keeps its documented exception (an observation naming no refs is unconstrained) at its own call site.

type ResourceSnapshot

type ResourceSnapshot struct {
	Ref     ResourceRef
	Version Version
	Fields  map[string]any
}

type ResourceVersion

type ResourceVersion struct {
	Ref     ResourceRef
	Version Version
}

type ResourceWrite

type ResourceWrite struct {
	Ref     ResourceRef
	Kind    OpKind
	BasedOn Version // expected current version; 0 for create
	Fields  map[string]any
}

type RuleDecision

type RuleDecision struct {
	Verdict  RuleVerdict
	Reasons  []string
	Proposal *ProposedEvent
	// ProposalActor is the TRUSTED origin actor of the carried Proposal — stamped by the RuleSet reducer from
	// the producing rule's Actor(), never by a rule's own output (json:"-" so an untrusted wasm rule cannot
	// forge it: the field is dropped on decode and re-set from the trusted Rule.Actor()). The server stamps the
	// bridge write identity from this instead of guessing the producer by scanning Handles/Emits.
	ProposalActor ActorID `json:"-"`
}

RuleDecision is a rule's output: a verdict plus (for propose) a Proposal. It is return-only — a rule never holds a Store/Kernel, so it can describe an effect but never perform one (S12).

type RuleVerdict

type RuleVerdict string

---- rule pre-gate (D4) ---- A rule is an ADMISSION CONTROLLER: it PROPOSES; it can NEVER write (S12). The kernel stays the only writer. The rich semantics live in this server-side pre-gate, not in the minimal kernel.

const (
	VerdictAllow   RuleVerdict = "allow"
	VerdictDeny    RuleVerdict = "deny"
	VerdictWarn    RuleVerdict = "warn"
	VerdictPropose RuleVerdict = "propose"
)

type Subscription

type Subscription struct {
	Actor       ActorID
	Refs        []ResourceRef
	PrivacyTier string
	// Budget is the context-budget tier (P4): a LOCAL derived-mirror shape (hot/warm/digest-only),
	// never a hub-side filter. It bounds how much of the pulled commit set the local packet renders;
	// the remote serves the same scoped set regardless (I11: remote settles, local decides). Empty
	// resolves to hot (full) — budget is not a security axis (the grant scope is), so the empty default
	// PRESERVES existing full-delivery behavior, mirroring ClampRefs's "empty requested = full scope".
	Budget BudgetTier
}

Subscription is a scope descriptor: which refs an actor may see, at what privacy tier. It lives in contract (not server) to avoid a projection<->server cycle (D11/blocker #3). The server builds an actor's scoped projection from its Subscription, and the projection identity (forActor) is the authenticated principal — a client never names its own scope on the wire (S9).

type SyncCommitResult

type SyncCommitResult struct {
	OriginReplicaID string      `json:"origin_replica_id"`
	LocalDecisionID string      `json:"local_decision_id"`
	ResourceRef     ResourceRef `json:"resource_ref"`
	Status          string      `json:"status"`
	Diagnostic      string      `json:"diagnostic,omitempty"`
}

type SyncPullRequest

type SyncPullRequest struct {
	ReplicaID    string        `json:"replica_id"`
	RemoteCursor string        `json:"remote_cursor"`
	Scopes       []ResourceRef `json:"scopes"`
}

type SyncPullResponse

type SyncPullResponse struct {
	Commits     []LocalCommit      `json:"commits"`
	Diagnostics []SyncCommitResult `json:"diagnostics"`
	NextCursor  string             `json:"next_cursor"`
}

type SyncPushRequest

type SyncPushRequest struct {
	ReplicaID string        `json:"replica_id"`
	BatchID   string        `json:"batch_id"`
	Commits   []LocalCommit `json:"commits"`
}

type SyncPushResponse

type SyncPushResponse struct {
	Accepted   []SyncCommitResult `json:"accepted"`
	Rejected   []SyncCommitResult `json:"rejected"`
	Conflicts  []SyncCommitResult `json:"conflicts"`
	NextCursor string             `json:"next_cursor,omitempty"`
}

type SyncStatusResponse

type SyncStatusResponse struct {
	Principal          ActorID           `json:"principal"`
	RemoteWorkspace    string            `json:"remote_workspace"`
	HubCommitsReceived int64             `json:"hub_commits_received"`
	HubCommitsServed   int64             `json:"hub_commits_served"`
	HubReplicaCursors  map[string]string `json:"hub_replica_cursors,omitempty"`
}

SyncStatusResponse carries the hub-side sync evidence. The three Hub* counters are the v1 ADDITIVE extension (sync-abi-v1 §3): total commits accepted into the hub log, total commits returned across pulls, and the last next_cursor served to each replica principal. A pre-counter hub omits them; clients treat absent as zero.

type Version

type Version int64 // per-resource; 1 on create; +1 each accepted write. NEVER global.

Jump to

Keyboard shortcuts

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