prompt

package
v0.1.12 Latest Latest
Warning

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

Go to latest
Published: Aug 12, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package prompt compiles the byte-exact provider stdin packet. It owns the only concatenation boundary between trusted template bytes and untrusted framed payloads.

Index

Constants

View Source
const (
	// MaxObjectiveBytes is the fixed maximum objective length. It is a byte
	// limit rather than a rune limit because objective provenance is byte exact.
	MaxObjectiveBytes = 12000
)
View Source
const (

	// TrustedLayerManifestAdapterParameter is the runtime adapter-parameter key
	// persisted in each publication prompt manifest.
	TrustedLayerManifestAdapterParameter = "trusted_layer_manifest"
)

Variables

This section is empty.

Functions

func CompleteStdinSHA256

func CompleteStdinSHA256(stdin []byte) string

CompleteStdinSHA256 returns the raw lowercase hexadecimal SOT wire identity.

Types

type CompileInput

type CompileInput struct {
	Scope                ScopeCoordinates
	ProjectContext       *Payload
	TaskRequirements     *Payload
	VisualAssetsManifest *Payload
	ReviewTarget         Payload
	PriorProviderOutput  *Payload
	PriorFinding         *Payload
	PriorReport          *Payload
	ExternalLogs         []Payload
}

CompileInput describes the only permitted frame cardinalities. The compiler determines every frame kind and order; callers cannot supply raw frames.

type CompiledPrompt

type CompiledPrompt struct {
	// contains filtered or unexported fields
}

CompiledPrompt is an immutable provider-stdin packet. It does not contain a provider, result, outcome, or any publication authority.

func (CompiledPrompt) CompleteStdinByteLength

func (prompt CompiledPrompt) CompleteStdinByteLength() int

func (CompiledPrompt) CompleteStdinSHA256

func (prompt CompiledPrompt) CompleteStdinSHA256() string

func (CompiledPrompt) ExactReplay

func (prompt CompiledPrompt) ExactReplay() bool

func (CompiledPrompt) ReplayedSourceInvocationID

func (prompt CompiledPrompt) ReplayedSourceInvocationID() (SourceInvocationID, bool)

func (CompiledPrompt) Scope

func (prompt CompiledPrompt) Scope() Scope

func (CompiledPrompt) Sections

func (prompt CompiledPrompt) Sections() []FramedSection

func (CompiledPrompt) Stdin

func (prompt CompiledPrompt) Stdin() []byte

func (CompiledPrompt) TrustedTemplate

func (prompt CompiledPrompt) TrustedTemplate() TrustedTemplate

func (CompiledPrompt) Validate

func (prompt CompiledPrompt) Validate() error

Validate verifies the exact stdin bytes, all frame constraints, stored section metadata, hash, scope, and replay marker.

func (CompiledPrompt) WireIdentity

func (prompt CompiledPrompt) WireIdentity() string

type Compiler

type Compiler struct {
	// contains filtered or unexported fields
}

Compiler owns trusted-template composition and the exact stdin wire format.

func NewCompiler

func NewCompiler(template TrustedTemplate, issuer InvocationIDIssuer) (*Compiler, error)

func (*Compiler) Compile

func (compiler *Compiler) Compile(input CompileInput) (CompiledPrompt, error)

Compile mints a fresh source and execution identity, frames the supplied untrusted data, and returns the exact provider stdin bytes.

func (*Compiler) Replay

func (compiler *Compiler) Replay(source CompiledPrompt) (CompiledPrompt, error)

Replay performs an exact replay: it preserves stored stdin and source identity, mints only a fresh execution identity, and marks the result as a replay. A caller wanting current templates must call Compile instead.

func (*Compiler) ReplayStored

func (compiler *Compiler) ReplayStored(stdin []byte, priorExecutionID ExecutionInvocationID) (CompiledPrompt, error)

ReplayStored reconstructs an exact replay from persisted stdin and the source process identity. It validates the complete frame grammar against the supplied trusted template, preserves the source scope and wire bytes, and mints only a fresh execution identity.

type ExecutionInvocationID

type ExecutionInvocationID struct {
	// contains filtered or unexported fields
}

ExecutionInvocationID identifies one provider process. Unlike source identities, it deliberately has no prefix.

func ParseExecutionInvocationID

func ParseExecutionInvocationID(value string) (ExecutionInvocationID, error)

func (ExecutionInvocationID) String

func (id ExecutionInvocationID) String() string

type FrameScope

type FrameScope struct {
	// contains filtered or unexported fields
}

FrameScope is the identity serialized in every untrusted frame. Execution identity is intentionally excluded from the frame grammar.

func NewFrameScope

func NewFrameScope(coordinates ScopeCoordinates, sourceInvocationID SourceInvocationID) (FrameScope, error)

func (FrameScope) AttemptID

func (scope FrameScope) AttemptID() domain.AttemptID

func (FrameScope) Coordinates

func (scope FrameScope) Coordinates() ScopeCoordinates

func (FrameScope) RoleTaskID

func (scope FrameScope) RoleTaskID() RoleTaskID

func (FrameScope) RunID

func (scope FrameScope) RunID() domain.RunID

func (FrameScope) SessionID

func (scope FrameScope) SessionID() domain.SessionID

func (FrameScope) SourceInvocationID

func (scope FrameScope) SourceInvocationID() SourceInvocationID

func (FrameScope) String

func (scope FrameScope) String() string

type FramedSection

type FramedSection struct {
	// contains filtered or unexported fields
}

FramedSection records one validated frame and exposes defensive copies of its untrusted payload and exact frame bytes.

func (FramedSection) FrameBytes

func (section FramedSection) FrameBytes() []byte

func (FramedSection) ID

func (section FramedSection) ID() string

func (FramedSection) Kind

func (section FramedSection) Kind() SectionKind

func (FramedSection) Payload

func (section FramedSection) Payload() []byte

func (FramedSection) PayloadByteLength

func (section FramedSection) PayloadByteLength() int

func (FramedSection) PayloadSHA256

func (section FramedSection) PayloadSHA256() string

func (FramedSection) Scope

func (section FramedSection) Scope() FrameScope

type IdentityError

type IdentityError struct {
	// contains filtered or unexported fields
}

IdentityError reports a failure while issuing, reserving, or constructing an invocation identity. It lets callers distinguish identity failures from input, template, and frame validation failures.

func (*IdentityError) Error

func (err *IdentityError) Error() string

func (*IdentityError) Operation

func (err *IdentityError) Operation() string

Operation identifies the identity operation that failed.

func (*IdentityError) Unwrap

func (err *IdentityError) Unwrap() error

type InvocationIDIssuer

type InvocationIDIssuer interface {
	NewSourceInvocationID() (SourceInvocationID, error)
	NewExecutionInvocationID() (ExecutionInvocationID, error)
}

InvocationIDIssuer issues fresh canonical identities. The compiler tracks all returned raw UUIDv7 values and rejects a repeated identity, including a source/execution namespace collision.

type Objective

type Objective struct {
	// contains filtered or unexported fields
}

Objective is an immutable limited-trust instruction. It is linted before it can be incorporated into a compiler-owned trusted layer.

func NewObjective

func NewObjective(content []byte) Objective

func (Objective) ByteLength

func (objective Objective) ByteLength() int

func (Objective) Bytes

func (objective Objective) Bytes() []byte

func (Objective) Lint

func (objective Objective) Lint() ObjectiveLintResult

type ObjectiveConflictClass

type ObjectiveConflictClass string

ObjectiveConflictClass is a frozen deterministic preflight category. It is deliberately not configurable: a lower-trust objective cannot redefine the constraints it is checked against.

const (
	ObjectiveRoleConflict        ObjectiveConflictClass = "role_conflict"
	ObjectiveRunTypeConflict     ObjectiveConflictClass = "run_type_conflict"
	ObjectiveSchemaConflict      ObjectiveConflictClass = "schema_conflict"
	ObjectiveSafetyConflict      ObjectiveConflictClass = "safety_conflict"
	ObjectiveAuthorityConflict   ObjectiveConflictClass = "authority_conflict"
	ObjectiveInstructionOverride ObjectiveConflictClass = "instruction_override"
	ObjectiveOversize            ObjectiveConflictClass = "oversize"
	ObjectiveInvalidEncoding     ObjectiveConflictClass = "invalid_encoding"
)

func (ObjectiveConflictClass) Valid

func (class ObjectiveConflictClass) Valid() bool

type ObjectiveDiagnostic

type ObjectiveDiagnostic struct {
	// contains filtered or unexported fields
}

ObjectiveDiagnostic identifies one deterministic conflict and gives a stable, actionable rewrite direction.

func (ObjectiveDiagnostic) Class

func (diagnostic ObjectiveDiagnostic) Class() ObjectiveConflictClass

func (ObjectiveDiagnostic) Message

func (diagnostic ObjectiveDiagnostic) Message() string

type ObjectiveLintResult

type ObjectiveLintResult struct {
	// contains filtered or unexported fields
}

ObjectiveLintResult reports all applicable frozen classes in canonical order. Its getter returns a new slice so callers cannot mutate the result.

func LintObjective

func LintObjective(content []byte) ObjectiveLintResult

LintObjective applies the frozen byte cap, UTF-8 check, and conservative ASCII phrase rules. It is intentionally deterministic rather than an LLM judgment, so a user can rewrite an objective from the exact diagnostics.

func (ObjectiveLintResult) Accepted

func (result ObjectiveLintResult) Accepted() bool

func (ObjectiveLintResult) ConflictClasses

func (result ObjectiveLintResult) ConflictClasses() []ObjectiveConflictClass

func (ObjectiveLintResult) Diagnostics

func (result ObjectiveLintResult) Diagnostics() []ObjectiveDiagnostic

func (ObjectiveLintResult) Err

func (result ObjectiveLintResult) Err() error

Err returns nil for an accepted objective and otherwise an actionable, deterministic summary suitable for preflight reporting.

type ParsedPrompt

type ParsedPrompt struct {
	// contains filtered or unexported fields
}

ParsedPrompt is the result of parsing a complete stdin byte stream before a provider process is started. It has no execution identity because execution identity is outside of the SOT frame grammar.

func ParseStdin

func ParseStdin(template TrustedTemplate, stdin []byte) (ParsedPrompt, error)

ParseStdin accepts only a complete, canonical SOT section-12/13 packet. It rejects malformed headers, bad lengths or hashes, scope divergence, missing review targets, wrong order, truncation, and any trailing byte.

func (ParsedPrompt) CompleteStdinByteLength

func (parsed ParsedPrompt) CompleteStdinByteLength() int

func (ParsedPrompt) CompleteStdinSHA256

func (parsed ParsedPrompt) CompleteStdinSHA256() string

func (ParsedPrompt) Scope

func (parsed ParsedPrompt) Scope() FrameScope

func (ParsedPrompt) Sections

func (parsed ParsedPrompt) Sections() []FramedSection

func (ParsedPrompt) Stdin

func (parsed ParsedPrompt) Stdin() []byte

func (ParsedPrompt) WireIdentity

func (parsed ParsedPrompt) WireIdentity() string

type Payload

type Payload struct {
	// contains filtered or unexported fields
}

Payload is an immutable untrusted byte value. It may be empty; a nil optional Payload pointer means that optional section is absent.

func NewPayload

func NewPayload(content []byte) Payload

func (Payload) ByteLength

func (payload Payload) ByteLength() int

func (Payload) Bytes

func (payload Payload) Bytes() []byte

func (Payload) SHA256

func (payload Payload) SHA256() string

type RoleTaskID

type RoleTaskID struct {
	// contains filtered or unexported fields
}

RoleTaskID is the canonical, opaque role-task identifier used in a frame scope. Domain role tasks deliberately do not expose an identifier because their aggregate is not an artifact identity.

func ParseRoleTaskID

func ParseRoleTaskID(value string) (RoleTaskID, error)

func (RoleTaskID) String

func (id RoleTaskID) String() string

type Scope

type Scope struct {
	// contains filtered or unexported fields
}

Scope binds the full canonical identity for one process invocation.

func NewScope

func NewScope(coordinates ScopeCoordinates, sourceInvocationID SourceInvocationID, executionInvocationID ExecutionInvocationID) (Scope, error)

func (Scope) AttemptID

func (scope Scope) AttemptID() domain.AttemptID

func (Scope) Coordinates

func (scope Scope) Coordinates() ScopeCoordinates

func (Scope) ExecutionInvocationID

func (scope Scope) ExecutionInvocationID() ExecutionInvocationID

func (Scope) FrameScope

func (scope Scope) FrameScope() FrameScope

func (Scope) RoleTaskID

func (scope Scope) RoleTaskID() RoleTaskID

func (Scope) RunID

func (scope Scope) RunID() domain.RunID

func (Scope) SessionID

func (scope Scope) SessionID() domain.SessionID

func (Scope) SourceInvocationID

func (scope Scope) SourceInvocationID() SourceInvocationID

type ScopeCoordinates

type ScopeCoordinates struct {
	// contains filtered or unexported fields
}

ScopeCoordinates are the stable identities shared by a source invocation and all of its exact replays.

func NewScopeCoordinates

func NewScopeCoordinates(sessionID domain.SessionID, runID domain.RunID, roleTaskID RoleTaskID, attemptID domain.AttemptID) (ScopeCoordinates, error)

func (ScopeCoordinates) AttemptID

func (coordinates ScopeCoordinates) AttemptID() domain.AttemptID

func (ScopeCoordinates) RoleTaskID

func (coordinates ScopeCoordinates) RoleTaskID() RoleTaskID

func (ScopeCoordinates) RunID

func (coordinates ScopeCoordinates) RunID() domain.RunID

func (ScopeCoordinates) SessionID

func (coordinates ScopeCoordinates) SessionID() domain.SessionID

type SectionKind

type SectionKind string

SectionKind identifies one untrusted frame type in the standalone grammar.

const (
	SectionProjectContext       SectionKind = "project_context"
	SectionTaskRequirements     SectionKind = "task_requirements"
	SectionVisualAssetsManifest SectionKind = "visual_assets_manifest"
	SectionReviewTarget         SectionKind = "review_target"
	SectionPriorProviderOutput  SectionKind = "prior_provider_output"
	SectionPriorFinding         SectionKind = "prior_finding"
	SectionPriorReport          SectionKind = "prior_report"
	SectionExternalLog          SectionKind = "external_log"
)

func (SectionKind) Valid

func (kind SectionKind) Valid() bool

type SourceInvocationID

type SourceInvocationID struct {
	// contains filtered or unexported fields
}

SourceInvocationID is the source identity shared by every frame in one newly composed packet.

func ParseSourceInvocationID

func ParseSourceInvocationID(value string) (SourceInvocationID, error)

func (SourceInvocationID) String

func (id SourceInvocationID) String() string

type TrustedLayer

type TrustedLayer struct {
	// contains filtered or unexported fields
}

TrustedLayer is an immutable compiler input. Callers provide individual trusted assets; only ComposeTrustedTemplate joins them into template bytes.

func NewTrustedLayer

func NewTrustedLayer(id, version string, content []byte) (TrustedLayer, error)

func (TrustedLayer) ByteLength

func (layer TrustedLayer) ByteLength() int

func (TrustedLayer) Bytes

func (layer TrustedLayer) Bytes() []byte

func (TrustedLayer) ID

func (layer TrustedLayer) ID() string

func (TrustedLayer) SHA256

func (layer TrustedLayer) SHA256() string

func (TrustedLayer) Version

func (layer TrustedLayer) Version() string

type TrustedLayerProvenance

type TrustedLayerProvenance struct {
	// contains filtered or unexported fields
}

TrustedLayerProvenance is one immutable ordered trusted-layer receipt.

func (TrustedLayerProvenance) ByteLength

func (provenance TrustedLayerProvenance) ByteLength() int

func (TrustedLayerProvenance) ID

func (provenance TrustedLayerProvenance) ID() string

func (TrustedLayerProvenance) Ordinal

func (provenance TrustedLayerProvenance) Ordinal() int

Ordinal is the one-based layer position in the trusted template.

func (TrustedLayerProvenance) SHA256

func (provenance TrustedLayerProvenance) SHA256() string

func (TrustedLayerProvenance) Version

func (provenance TrustedLayerProvenance) Version() string

type TrustedTemplate

type TrustedTemplate struct {
	// contains filtered or unexported fields
}

TrustedTemplate holds exact immutable trusted bytes. Its byte getter always returns a copy, and the compiler copies it again when constructed.

func ComposeTrustedTemplate

func ComposeTrustedTemplate(id, version string, layers ...TrustedLayer) (TrustedTemplate, error)

ComposeTrustedTemplate is the compiler-owned trusted-layer composer. It inserts exactly one blank line between consecutive trusted layers and never exposes a raw trusted-byte concatenation helper.

func NewTrustedTemplate

func NewTrustedTemplate(id, version string, content []byte) (TrustedTemplate, error)

func NewTrustedTemplateWithOpaqueLayer

func NewTrustedTemplateWithOpaqueLayer(id, version string, content []byte) (TrustedTemplate, error)

NewTrustedTemplateWithOpaqueLayer constructs a direct template with explicit single-layer provenance. NewTrustedTemplate remains provenance-free for backward compatibility.

func (TrustedTemplate) ByteLength

func (template TrustedTemplate) ByteLength() int

func (TrustedTemplate) Bytes

func (template TrustedTemplate) Bytes() []byte

func (TrustedTemplate) ID

func (template TrustedTemplate) ID() string

func (TrustedTemplate) SHA256

func (template TrustedTemplate) SHA256() string

func (TrustedTemplate) TrustedLayerManifest

func (template TrustedTemplate) TrustedLayerManifest() []TrustedLayerProvenance

TrustedLayerManifest returns caller-owned ordered immutable layer receipts. Direct NewTrustedTemplate values intentionally return an empty manifest.

func (TrustedTemplate) TrustedLayerManifestJSON

func (template TrustedTemplate) TrustedLayerManifestJSON() (string, error)

TrustedLayerManifestJSON returns a deterministic bounded representation for runtime adapter parameters and publication manifests.

func (TrustedTemplate) Version

func (template TrustedTemplate) Version() string

Jump to

Keyboard shortcuts

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