Skip to main content

When to Use

When encoding/decoding STRATT prompt units for wire transfer between CLI, R2, and MERIDIAN. Every prompt unit in transit is wrapped with a 128-bit SPUH header.

Bit Layout (16 bytes)

Byte 0:  [Version 4b][Type 4b]
Byte 1:  [Domain 4b][Status 4b]
Byte 2:  MajVer (8b)
Byte 3:  MinVer (8b)
Byte 4:  PatchVer (8b)
Byte 5-6: SchemaVer (16b, big-endian)
Byte 7:  Flags (8b)
Byte 8-15: Blake3 fingerprint prefix (64b, big-endian)

Enum Bit Values

Type: role=0001, rule=0010, task=0011, chain=0100, fragment=0101 Domain: dev=0001, neuro=0010, finance=0011, nutrition=0100, legal=0101, film=0110, artist=0111, core=1000, shared=1001 Status: draft=0001, review=0010, stable=0011, deprecated=0100, tampered=0101, tombstoned=0110

Flag Bits (Byte 7)

BitNameMeaning
b0gate_presentChain contains gate checkpoints
b1protectedUnit is protected (cannot be removed from chains)
b2core_injectedCore rules were auto-injected at execution
b3crdt_dirtyUnresolved CRDT merge pending
b4-b7reservedMust be 0

Usage

import { encodeSpuh, decodeSpuh, fingerprintToPrefix } from "@stratt/schema";

const fields = {
  version: 1,
  type: "task" as const,
  domain: "dev" as const,
  status: "stable" as const,
  major: 1, minor: 2, patch: 3,
  schemaVersion: 1,
  flags: { gatePresent: false, protected: false, coreInjected: false, crdtDirty: false },
  fingerprintPrefix: fingerprintToPrefix("blake3:a1d94a025f820f16..."),
};

const buf: Uint8Array = encodeSpuh(fields);  // 16 bytes
const decoded = decodeSpuh(buf);             // round-trips exactly

Gotcha: BigInt Not JSON-Serializable

The fingerprintPrefix field is a bigint. Calling JSON.stringify() on SpuhFields will throw. Convert to hex string first:
const hex = decoded.fingerprintPrefix.toString(16).padStart(16, "0");

Gotcha: Byte Order

All multi-byte fields use big-endian (network byte order). SchemaVer bytes 5-6: high byte first. Fingerprint prefix bytes 8-15: most significant byte first.