PtcRunner.Kernel.SafeMetadata (PtcRunner v0.14.0)

Copy Markdown View Source

Validates the closed, payload-free metadata vocabulary used by canonical events.

Safe metadata is intentionally less expressive than general JSON. Every caller-supplied name/model/provider label is reduced to a one-way SHA-256 fingerprint before it reaches a canonical event. Tags and workflow annotations use finite semantic vocabularies: types and keys are closed, and enumerated values are closed. A phased workflow annotation may also carry mission, a bounded identifier rather than a free string. Prompts, credentials, generated source, and arbitrary application data therefore require private inspection.

Summary

Functions

Returns whether an annotation belongs to the finite canonical vocabulary.

Builds the public usage.capability_refusals key for one error envelope.

Maximum distinct closed-class keys retained in usage.capability_refusals.

Projects an explicit failure value to bounded, payload-free taxonomy.

Returns the canonical non-reversible fingerprint for one bounded identifier.

Returns whether a value is an already-normalized canonical-label map.

Projects an agent LLM failure to one closed, payload-free provider class.

Validates labels and fingerprints caller-defined identifier fields.

Projects a Lisp capability error envelope to a payload-free rejection class.

Functions

annotation?(arg1, data)

@spec annotation?(term(), term()) :: boolean()

Returns whether an annotation belongs to the finite canonical vocabulary.

"progress" carries exactly one enumerated stage. "agent-action" is the shipped agent loop's coarse per-turn record: exactly the keys turn (an integer from 0 through 127, matching the loop's maximum turn count) and kind (one of tool-call, protocol-error, provider-error, or max-calls, or model-output-truncated). A phased agent run adds exactly phase (0 through 7), phase_turn (0 through 127), and mission (the phase's mission name) — all three or none, so a partial shape stays out of the vocabulary. It never carries detailed reasons, generated source, or model content — those stay in the agent's own history and, when enabled, in private inspection records.

capability_refusal_key(environment, result)

@spec capability_refusal_key(:workflow | :mission, map()) :: binary()

Builds the public usage.capability_refusals key for one error envelope.

The key is "<environment>/<kind>/<reason>". A known atom stays readable, an unrecognized atom is the same one-way fingerprint rejection_class/1 uses, and a missing or non-atom field is unknown. Distinct keys are capped by capability_refusal_map_limit/0; further classes increment $overflow.

capability_refusal_map_limit()

@spec capability_refusal_map_limit() :: 2

Maximum distinct closed-class keys retained in usage.capability_refusals.

Terminal usage admission reserves this many fingerprint-length keys plus $overflow. Two named classes is the largest such map that still admits an empty environment at the 7_000-byte event_payload_bytes floor used by terminal preflight. Further classes increment $overflow.

failure_taxonomy(value)

@spec failure_taxonomy(term()) :: map()

Projects an explicit failure value to bounded, payload-free taxonomy.

Known framework categories remain readable. An application-defined category is represented only by a stable fingerprint, so repeated failures can be grouped without putting the caller's value into a public error or trace. Values without a scalar kind field produce no public taxonomy.

fingerprint(value)

@spec fingerprint(binary()) :: binary()

Returns the canonical non-reversible fingerprint for one bounded identifier.

labels?(labels)

@spec labels?(term()) :: boolean()

Returns whether a value is an already-normalized canonical-label map.

llm_provider_failure(value)

@spec llm_provider_failure(term()) :: map()

Projects an agent LLM failure to one closed, payload-free provider class.

normalize_labels(labels)

@spec normalize_labels(term()) :: {:ok, map()} | {:error, :invalid_safe_metadata}

Validates labels and fingerprints caller-defined identifier fields.

rejection_class(result)

@spec rejection_class(term()) :: map()

Projects a Lisp capability error envelope to a payload-free rejection class.

Known Kernel kind and reason atoms remain readable on canonical capability-stopped events. An unrecognized atom is retained only as a one-way fingerprint so a missed Kernel class still groups without putting the atom name on the public trace. Non-atoms, details, and messages produce no public fields.