source

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package source prepares a small, canonical and privacy-bounded source window for continuity extraction. It deliberately knows nothing about provider wire DTOs or the implementation of structured plan carriers.

Index

Constants

View Source
const (
	EnvelopeVersion = 1

	UntrustedOpen  = "[UNTRUSTED TOOL DATA]\n"
	UntrustedClose = "\n[/UNTRUSTED TOOL DATA]"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type CarrierRecognizer

type CarrierRecognizer interface {
	Recognize(item lipapi.Item) (StructuredCarrier, bool)
}

CarrierRecognizer recognizes provider-neutral structured plan carriers. It must return a bounded, canonical payload and must not perform I/O.

type CarrierRecognizerFunc

type CarrierRecognizerFunc func(item lipapi.Item) (StructuredCarrier, bool)

CarrierRecognizerFunc adapts a pure function to CarrierRecognizer.

func (CarrierRecognizerFunc) Recognize

type Config

type Config struct {
	MaxBytes              int
	MaxEntries            int
	MaxEntryBytes         int
	MaxCarrierBytes       int
	MaxUntrustedToolBytes int
}

Config bounds source retention. Zero values are replaced by DefaultConfig.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns the conservative source bounds used by the feature.

type Eligibility

type Eligibility struct {
	Eligible       bool
	Signal         EligibilitySignal
	CandidateCount int
}

Eligibility is a cost gate only. Eligible means "a semantic extraction may be worth paying for"; it does not assert that any user decision is valid or accepted.

func EvaluateEligibility

func EvaluateEligibility(in EligibilityInput) Eligibility

EvaluateEligibility applies narrow explicit-language and source-shape heuristics. Generic words such as "plan" by themselves never trigger.

type EligibilityInput

type EligibilityInput struct {
	Entries                []Entry
	DeterministicSatisfied bool
	CapsuleAbsent          bool
	CapsuleStale           bool
	// OnlyNew restricts evaluation to entries marked New. It is useful to
	// evaluate an incremental delta while direct callers can evaluate a full
	// bounded window without setting New on every fixture.
	OnlyNew bool
}

EligibilityInput contains only sanitized source and local state. Untrusted records are deliberately ignored as semantic triggers.

type EligibilitySignal

type EligibilitySignal string

EligibilitySignal explains the bounded, local reason a semantic call may add information. It is diagnostic classification, never accepted intent.

const (
	SignalNone                 EligibilitySignal = "none"
	SignalExplicitUserDecision EligibilitySignal = "explicit_user_decision"
	SignalPlanAccepted         EligibilitySignal = "plan_accepted_or_corrected"
	SignalStaleCapsule         EligibilitySignal = "stale_or_missing_capsule"
)

type Entry

type Entry struct {
	Kind             EntryKind          `json:"kind"`
	ItemID           string             `json:"item_id,omitempty"`
	ItemIndex        int                `json:"item_index"`
	Role             lipapi.Role        `json:"role,omitempty"`
	Text             string             `json:"text,omitempty"`
	Carrier          *StructuredCarrier `json:"carrier,omitempty"`
	Untrusted        bool               `json:"untrusted,omitempty"`
	DecisionRelevant bool               `json:"decision_relevant,omitempty"`
	PlanningRelevant bool               `json:"planning_relevant,omitempty"`
	New              bool               `json:"new,omitempty"`
	// contains filtered or unexported fields
}

Entry is a bounded source record. Text and carrier payload are egress data; metadata fields are content-free classification only.

type EntryKind

type EntryKind string

EntryKind identifies the small set of source records the extractor may see.

const (
	EntryUserDecision      EntryKind = "user_decision"
	EntryUserText          EntryKind = "user_text"
	EntryAssistantPlan     EntryKind = "assistant_plan"
	EntryStructuredCarrier EntryKind = "structured_carrier"
	EntryUntrustedTool     EntryKind = "untrusted_tool"
)

type Envelope

type Envelope struct {
	Version       int           `json:"version"`
	HighWatermark HighWatermark `json:"high_watermark"`
	Entries       []Entry       `json:"entries,omitempty"`
	Bytes         int           `json:"-"`
}

Envelope is the bounded canonical source window. It is not a transcript and contains no route, branch, session, or provider-specific metadata.

func (Envelope) Canonical

func (e Envelope) Canonical() string

Canonical returns stable JSON suitable for hashing or test comparisons.

type HighWatermark

type HighWatermark struct {
	ItemCount int    `json:"item_count"`
	Digest    string `json:"digest"`
}

HighWatermark is deterministic and content-free. ItemCount advances over every walked canonical item, including dropped items, while Digest detects a changed prefix before incremental preparation is allowed to append.

type Input

type Input struct {
	Call       lipapi.Call
	Existing   Envelope
	Previous   HighWatermark
	Recognizer CarrierRecognizer
	Redactor   Redactor
	Config     Config
}

Input is the pure preparation input. Existing is copied and only the new suffix is walked when Previous proves the prefix unchanged.

type MatcherRedactor

type MatcherRedactor struct {
	Matcher secretguard.Matcher
}

MatcherRedactor adapts the existing secretguard.Matcher contract to the source package's smaller redaction interface. Findings are intentionally discarded: source preparation never exposes secret metadata or excerpts.

func (MatcherRedactor) Redact

func (r MatcherRedactor) Redact(ctx context.Context, in string) (string, error)

type Prepared

type Prepared struct {
	Envelope      Envelope
	NewEntries    []Entry
	HighWatermark HighWatermark
	Candidate     bool
}

Prepared is the bounded source result. NewEntries contains only records discovered after the accepted prefix and is safe for incremental scheduling.

func Prepare

func Prepare(ctx context.Context, in Input) (Prepared, error)

Prepare walks a canonical call without mutating it or making external calls. User decision text has highest priority, followed by relevant assistant planning and recognized structured carriers. Ordinary tools, media, reasoning, logs and dumps are omitted.

type Redactor

type Redactor interface {
	Redact(context.Context, string) (string, error)
}

Redactor is the consumed privacy seam. Implementations own secret matching and return only the transformed string; no secret catalog is exposed here.

type StructuredCarrier

type StructuredCarrier struct {
	Type    string `json:"type"`
	Version int    `json:"version"`
	Payload string `json:"payload"`
}

StructuredCarrier is the narrow carrier seam consumed by Prepare. A carrier implementation can recognize its own canonical shape and return bounded JSON without this package importing that implementation.

Jump to

Keyboard shortcuts

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