Spectre.Skill.PromptBudget (Spectre v0.3.0)

Copy Markdown View Source

Closed per-Skill prompt budget derived from canonical fragments.

A budget is part of the Skill Definition rather than a best-effort option at render time. Runtime Skills must cap every fragment, and the sum of those caps must fit inside the Skill ceiling. Compiled Skills may retain legacy uncapped fragments; their current content estimate is charged in full.

Summary

Functions

Returns the canonical SHA-256 budget digest.

Restores and validates a budget from canonical data.

Builds and validates a budget from canonical fragments.

Builds a prompt budget or raises with its stable validation reason.

Returns the current Skill prompt-budget schema version.

Returns the portable canonical representation.

Types

t()

@type t() :: %Spectre.Skill.PromptBudget{
  estimated_tokens: non_neg_integer(),
  fragment_count: non_neg_integer(),
  reserved_tokens: non_neg_integer(),
  schema_version: pos_integer(),
  token_cap: pos_integer()
}

Functions

digest(budget)

@spec digest(t()) :: String.t()

Returns the canonical SHA-256 budget digest.

from_data(value)

@spec from_data(map()) :: {:ok, t()} | {:error, term()}

Restores and validates a budget from canonical data.

new(fragments, opts \\ [])

@spec new(
  [Spectre.Prompt.Fragment.t() | map()],
  keyword()
) :: {:ok, t()} | {:error, term()}

Builds and validates a budget from canonical fragments.

new!(fragments, opts \\ [])

@spec new!(
  [Spectre.Prompt.Fragment.t() | map()],
  keyword()
) :: t()

Builds a prompt budget or raises with its stable validation reason.

schema_version()

@spec schema_version() :: pos_integer()

Returns the current Skill prompt-budget schema version.

to_data(budget)

@spec to_data(t()) :: map()

Returns the portable canonical representation.