receipt

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 10, 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.

README

qmax-receipt

The shared, versioned schema behind QualityMax's "Receipts, not promises" trust model. Every QualityMax agent that touches the network — the qmax CLI (crawl / test execution / CI) and the qmax-code terminal agent — imports this module and emits the same Exposure Receipt: a per-run, customer-held manifest of every outbound request (destination, category, byte size, and content SHA-256 — never content), signed with ed25519.

One schema, one signer, one Verify. A receipt written by either agent is validated by the same code (and re-implementable in any language off the pinned receipt_version).

What it is / isn't

  • Is: a tamper-evident record of what could have left the boundary — hashes and sizes, so the receipt itself is non-sensitive and safe to hand a security reviewer to diff against their own firewall logs.
  • Isn't: proof of honesty. Verify proves provenance (this key produced this receipt), not that the agent declared everything. Trust roots in open auditable source + each agent's static egress guard + customer log-diffing — never the signature alone. Do not describe a signed receipt as "trustworthy."

Usage

import receipt "github.com/Quality-Max/qmax-receipt"

func init() {
    receipt.AgentVersion = version
    // qmax CLI keeps the default (~/.qamax); qmax-code overrides:
    // receipt.BaseDir = filepath.Join(home, ".qmax-code")
}

// Per run (a CLI command, a daemon assignment, a qmax-code session):
ctx, r := receipt.Begin(ctx, "crawl")     // or receipt.NewCurrent("cli")
// ...the agent's httpx RoundTripper calls r.Record(entry) for each request...
path, _ := r.Finalize()                   // signs + writes BaseDir/receipts/<id>.json

// Offline verification:
r2, _ := receipt.Load(path)
err := receipt.Verify(r2)

Entry.Category is a free-form string: this module never enumerates categories. Each agent supplies its own taxonomy and classifier, then records a category string. Templatize (id-collapsing) is shared here because every agent needs it.

What lives here vs in each agent

Here (shared contract) Per-agent (in each repo)
Entry / Receipt / Summary types Classify() + category constants
run routing, Record, Finalize httpx recording RoundTripper + static guard
ed25519 sign / Verify policy runtime allow-list (warn/strict)
Load / List, Templatize egress-site wiring

Schema version

Version = "1". Bump only on a wire-format change. The signed payload is the encoding/json marshal of the Receipt with Signature omitted — struct-field order + sorted map keys make it deterministic and cross-language reproducible.

License

TBD before publishing (see docs/RECEIPT_SHARED_MODULE_SCOPE.md). A permissive license (Apache-2.0 / MIT) fits a verifiable schema contract better than the FSL used for the agent binaries — the whole point is that anyone can verify.

Documentation

Overview

Package receipt implements the Exposure Receipt: a per-run, customer-held manifest of every outbound request an agent made — destination, category, byte size, and content SHA-256 (NOT content). It is the mechanism behind the "Receipts, not promises" trust model.

This is the SHARED, versioned schema contract imported by every QualityMax agent that emits receipts (the `qmax` CLI and the `qmax-code` terminal agent). The wire format is pinned by Version; a verifier in any language can reproduce the signed bytes (see sign.go). Each agent supplies its own traffic taxonomy — this package treats Entry.Category as a free-form string and never enumerates categories.

Quality commitments enforced here:

  • Fail loud, never silent: a request with no receipt-bearing context records into a process-global "current" run, then an "untracked" fallback (with a one-time warning) — entries are never dropped.
  • Concurrency-safe: the seq counter is per-receipt and the entry slice is mutex-guarded, so concurrent goroutines never interleave or race.
  • Deterministic signing: receipts are signed over encoding/json output, whose field order (struct order) and map-key order (sorted) are stable.

This package intentionally does NOT import net/http: it operates on plain strings, keeping all net/http usage inside each agent's httpx chokepoint.

Index

Constants

View Source
const Version = "1"

Version of the receipt schema. Bump only on a wire-format change; both agents and any external verifier key off this.

Variables

View Source
var AgentVersion = "dev"

AgentVersion is stamped into each receipt; set by the importing agent at init.

View Source
var BaseDir = defaultBaseDir()

BaseDir is the directory under which receipts (BaseDir/receipts/) and the signing key (BaseDir/receipt_ed25519.seed) are stored. Defaults to ~/.qamax, preserving the qmax CLI's original layout; qmax-code sets this to ~/.qmax-code at init so the two agents keep separate identities and stores.

View Source
var BuildSHA = "dev"

BuildSHA identifies the agent build that produced a receipt. Override via -ldflags "-X github.com/Quality-Max/qmax-receipt.BuildSHA=<sha>".

Functions

func List

func List() ([]string, error)

List returns the paths of all receipt files, newest filesystem-modified last.

func ReceiptsDir

func ReceiptsDir() (string, error)

ReceiptsDir is the directory where finalized receipts are written.

func Templatize

func Templatize(path string) string

Templatize collapses id-like path segments (numeric, uuid, long hex) to {id} so receipts are comparable across runs and don't leak ids into the path. It is generic and shared by every agent's classifier before recording an Entry.Path.

func Verify

func Verify(r *Receipt) error

Verify checks a receipt's embedded signature against its embedded public key. It proves PROVENANCE (this key produced this receipt), not honesty — trust roots in open source + the static egress guard + the customer diffing the receipt against their own firewall logs, never the signature alone.

Types

type Entry

type Entry struct {
	Seq        int       `json:"seq"`
	Timestamp  time.Time `json:"timestamp"`
	Method     string    `json:"method"`
	Host       string    `json:"host"`
	Path       string    `json:"path"` // templatized: /api/agent/{id}/crawl/{id}/snapshot
	Category   string    `json:"category"`
	Model      *string   `json:"model"`
	ReqBytes   int64     `json:"req_bytes"`
	ReqSHA256  string    `json:"req_sha256"`
	RespStatus int       `json:"resp_status"`
	RespBytes  int64     `json:"resp_bytes"`
	Allowed    bool      `json:"allowed"`
	Rule       string    `json:"rule"`
	Note       string    `json:"note,omitempty"` // e.g. "blocked-by-egress-policy", "transport-error: ..."
}

Entry is a single recorded outbound request. It stores a hash and size, never content — so the receipt itself is non-sensitive and safe to share.

type Receipt

type Receipt struct {
	ReceiptVersion string     `json:"receipt_version"`
	RunID          string     `json:"run_id"`
	RunKind        string     `json:"run_kind"`
	AgentVersion   string     `json:"agent_version"`
	AgentBuildSHA  string     `json:"agent_build_sha"`
	StartedAt      time.Time  `json:"started_at"`
	FinishedAt     *time.Time `json:"finished_at,omitempty"`
	Destinations   []string   `json:"destinations"`
	Entries        []Entry    `json:"entries"`
	Summary        Summary    `json:"summary"`
	Signature      *Signature `json:"signature,omitempty"`
	// contains filtered or unexported fields
}

Receipt is one run's manifest. The Signature field is omitted while signing (omitempty), so the signed payload is everything else, deterministically.

func Begin

func Begin(ctx context.Context, kind string) (context.Context, *Receipt)

Begin creates a receipt and returns a context carrying it. Use this for concurrent work (each daemon assignment/crawl session, or a qmax-code session) so entries route to the right run regardless of the process-global current.

func FromContext

func FromContext(ctx context.Context) *Receipt

FromContext resolves the active receipt: context first, then process-global current, then a fail-loud untracked fallback. It never returns nil and never drops an entry on the floor.

func Load

func Load(path string) (*Receipt, error)

Load reads and parses a receipt JSON file from disk.

func NewCurrent

func NewCurrent(kind string) *Receipt

NewCurrent creates a receipt and installs it as the process-global current run. Use this for single-run-per-process work (CLI commands, the daemon control plane). Returns the receipt so the caller can Finalize it.

func (*Receipt) EntryCount

func (r *Receipt) EntryCount() int

EntryCount returns the number of recorded entries (concurrency-safe).

func (*Receipt) Finalize

func (r *Receipt) Finalize() (string, error)

Finalize stamps the summary, signs, and writes the receipt to BaseDir/receipts/<run_id>.json. It returns the written path.

func (*Receipt) Record

func (r *Receipt) Record(e Entry)

Record appends an entry to the receipt, assigning a per-receipt sequence number. Safe for concurrent callers.

type Signature

type Signature struct {
	Alg       string `json:"alg"`
	PublicKey string `json:"public_key"` // base64 raw ed25519 public key — receipt is self-verifying
	Value     string `json:"value"`      // base64 signature over the canonical payload
}

Signature is the detached ed25519 signature over the receipt payload.

type Summary

type Summary struct {
	TotalRequests int            `json:"total_requests"`
	TotalReqBytes int64          `json:"total_req_bytes"`
	ByCategory    map[string]int `json:"by_category"`
	Violations    int            `json:"violations"`
}

Summary is the at-a-glance roll-up a reviewer reads first.

Jump to

Keyboard shortcuts

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