Spectre.Definition (Spectre v0.3.0)

Copy Markdown View Source

Compiled behavioral description shared by Agents and Skills.

Agent and Skill DSL modules compile their declarations once and expose one immutable definition. Runtime code uses this module to resolve scoped rules, policies, prompt roots, protections, hooks, and mounted Skill configuration without flattening away ownership.

Summary

Functions

Returns every Agent and mounted-Skill action hook after logical binding.

Returns the Agent's pre-execution action guards after logical binding.

Lowers a compiled Agent or Skill module into its portable canonical IR.

Returns the canonical Definition or raises with its stable lowering reason.

Returns the compiled definition exposed by a DSL module.

Returns a definition or raises an ArgumentError with a stable reason.

Resolves the definition active for a route scope.

Returns the definition for a scope or raises an ArgumentError.

Returns Agent injections followed by the active Skill injections.

Composes the compiled source into a sealed Definition Manifest V2.

Composes a compiled Definition Manifest or raises.

Returns the mount for a scope when it exists.

Builds a normalized compiled definition.

Resolves a policy reference to its definition and owning scope.

Returns the local policy name from a scoped reference.

Returns a stable policy reference for a scope.

Returns the scope carried by a policy reference.

Resolves an owning module's prompt root within an Agent composition.

Returns every protection visible to an Agent with Skill action bindings and scoped policy references applied.

Returns every rule visible to an Agent with mount ownership materialized.

Types

kind()

@type kind() :: :agent | :skill

scope()

@type scope() :: :agent | {:skill, term()}

t()

@type t() :: %Spectre.Definition{
  after_actions: [map()],
  before_actions: [map()],
  change_surface: Spectre.Morph.Surface.t() | nil,
  config: keyword(),
  extensions: [Spectre.Extension.Mount.t()],
  id: term(),
  injections: [term()],
  kind: kind(),
  owner: module(),
  policies: map(),
  prompt_root: String.t(),
  protections: [map()],
  requirements: [map()],
  router: keyword(),
  rules: [map()],
  skills: [Spectre.Skill.Mount.t()],
  stack: module() | nil,
  stack_refs: [Spectre.Stack.Ref.t()],
  version: pos_integer()
}

Functions

after_actions(agent)

@spec after_actions(module()) :: [map()]

Returns every Agent and mounted-Skill action hook after logical binding.

before_actions(agent)

@spec before_actions(module()) :: [map()]

Returns the Agent's pre-execution action guards after logical binding.

Guards are Agent-owned infrastructure: Skills cannot contribute them.

canonical(module, opts \\ [])

@spec canonical(
  module(),
  keyword()
) :: {:ok, Spectre.Definition.Canonical.t()} | {:error, term()}

Lowers a compiled Agent or Skill module into its portable canonical IR.

This snapshots governed prompt assets, replaces executable callbacks with compiled code references, and returns the content-addressable Definition envelope used by projections.

canonical!(module, opts \\ [])

@spec canonical!(
  module(),
  keyword()
) :: Spectre.Definition.Canonical.t()

Returns the canonical Definition or raises with its stable lowering reason.

fetch(module)

@spec fetch(module()) :: {:ok, t()} | {:error, term()}

Returns the compiled definition exposed by a DSL module.

Legacy Agent modules that only expose the original metadata callbacks are normalized into a definition so runtime callers have one access path.

fetch!(module)

@spec fetch!(module()) :: t()

Returns a definition or raises an ArgumentError with a stable reason.

for_scope(agent, arg2)

@spec for_scope(module(), scope()) :: {:ok, t()} | {:error, term()}

Resolves the definition active for a route scope.

for_scope!(agent, scope)

@spec for_scope!(module(), scope()) :: t()

Returns the definition for a scope or raises an ArgumentError.

injections(agent, scope)

@spec injections(module(), scope()) :: [term()]

Returns Agent injections followed by the active Skill injections.

Scope-specific ordering is handled later by Spectre.Prompt.Plan; this function only selects definitions participating in the current route.

manifest(module, opts \\ [])

@spec manifest(
  module(),
  keyword()
) :: {:ok, Spectre.Definition.Manifest.t()} | {:error, term()}

Composes the compiled source into a sealed Definition Manifest V2.

Stack V1 declarations are treated as requests and intersected with the trusted :authority_ceiling. Omitting that ceiling produces no grants.

manifest!(module, opts \\ [])

@spec manifest!(
  module(),
  keyword()
) :: Spectre.Definition.Manifest.t()

Composes a compiled Definition Manifest or raises.

mount(agent, arg2)

@spec mount(module(), scope()) :: Spectre.Skill.Mount.t() | nil

Returns the mount for a scope when it exists.

new(attrs)

@spec new(map() | keyword()) :: t()

Builds a normalized compiled definition.

policy(agent, name)

@spec policy(module(), term()) :: {:ok, map(), scope()} | {:error, term()}

Resolves a policy reference to its definition and owning scope.

Legacy atom references resolve in Agent scope. Skill policy references are represented as {{:skill, mount_id}, policy_name}.

policy_name(name)

@spec policy_name(term()) :: atom() | nil

Returns the local policy name from a scoped reference.

policy_ref(scope, name)

@spec policy_ref(scope(), atom()) :: atom() | {scope(), atom()}

Returns a stable policy reference for a scope.

policy_scope(arg1)

@spec policy_scope(term()) :: scope()

Returns the scope carried by a policy reference.

prompt_root(agent, scope)

@spec prompt_root(module(), scope()) :: {:ok, String.t()} | {:error, term()}

Resolves an owning module's prompt root within an Agent composition.

protections(agent)

@spec protections(module()) :: [map()]

Returns every protection visible to an Agent with Skill action bindings and scoped policy references applied.

rules(agent)

@spec rules(module()) :: [map()]

Returns every rule visible to an Agent with mount ownership materialized.