# `Spectre.Prompt.Fragment`
[🔗](https://github.com/elchemista/spectre/blob/0.4.0/lib/spectre/prompt/fragment.ex#L1)

Resolved or canonical prompt content with its composition metadata.

Runtime fragments are built with `new/3`. Content-addressed Definition
fragments are built with `canonical/1`; those fragments reject EEx and use a
closed `{{path.to.value}}` placeholder grammar with an explicit schema.

# `t`

```elixir
@type t() :: %Spectre.Prompt.Fragment{
  budget_class: :small | :standard | :large,
  condition_ref: map() | nil,
  content: String.t() | nil,
  digest: String.t() | nil,
  granted_priority: :low | :normal | :high,
  id: term(),
  metadata: map(),
  placeholders: map(),
  position: Spectre.Prompt.Operation.position(),
  provenance: map(),
  requested_priority: :low | :normal | :high,
  schema_version: pos_integer(),
  scope: term(),
  source: Spectre.Prompt.Operation.source() | :base | map(),
  target: Spectre.Prompt.Operation.target(),
  token_cap: pos_integer() | nil,
  trust: :instruction | :data,
  visibility: :private | :agent | :operator | :public
}
```

# `base`

```elixir
@spec base(String.t()) :: t()
```

Builds the base task fragment selected by `ask`.

# `canonical`

```elixir
@spec canonical(map() | keyword()) :: {:ok, t()} | {:error, term()}
```

Builds a governed, digest-addressed prompt fragment.

Canonical content may be static text or a template containing only declared
`{{path.to.value}}` placeholders. Dynamic providers use `content: nil` and
must remain `context:data` fragments.

# `canonical!`

```elixir
@spec canonical!(map() | keyword()) :: t()
```

Builds a canonical fragment or raises with its stable validation reason.

# `canonical_data`

```elixir
@spec canonical_data(t()) :: map()
```

Returns the portable data included in a canonical fragment digest.

# `close_template`

```elixir
@spec close_template(String.t()) :: {:ok, String.t(), map()} | {:error, term()}
```

Migrates the safe subset of compiled `.text.heex` assets to closed templates.

Only direct assign paths such as `<%= @input.text %>` are accepted. Any
remaining EEx tag is rejected instead of being copied into runtime data.

# `new`

```elixir
@spec new(Spectre.Prompt.Operation.t(), String.t(), map()) :: t()
```

Builds a resolved prompt fragment from an operation.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
