Documentation
¶
Overview ¶
Package agentcontext preserves source-asserted agent records separately from kernel observations and analysis. Missing source information remains unknown.
Index ¶
- Constants
- Variables
- func HookCaptureDiagnostic(code string) []byte
- func Number(n int64) *int64
- func RetainHookEvent(data []byte, policy CapturePolicy) ([]byte, error)
- func ToolNodeID(e Entry) string
- type Candidate
- type CaptureOmission
- type CapturePolicy
- type ContentRef
- type Counts
- type Coverage
- type DiscoverOptions
- type Entry
- type EntryLinks
- type GraphLink
- type Inventory
- type Issue
- type Overview
- type Page
- type PageOptions
- type ParseBudget
- type ParseOptions
- type Parsed
- type PriorRange
- type Record
- type SaveResult
- type SelectOptions
- type SelectedSource
- type Selection
- type Service
- func (s Service) CompareSnapshots(ctx context.Context, runID, leftID, rightRunID, rightID string) (SnapshotComparison, error)
- func (s Service) EnsureCapturePolicy(ctx context.Context, run string) (CapturePolicy, error)
- func (s Service) Entries(ctx context.Context, opts PageOptions) (Page, error)
- func (s Service) EnumerateSessions(ctx context.Context, opts SessionEnumerationOptions) ([]SessionIdentity, error)
- func (s Service) ImportFile(ctx context.Context, runID string, opts ParseOptions) (SaveResult, error)
- func (s Service) Links(ctx context.Context, runID, entryID string) (EntryLinks, error)
- func (s Service) Overview(ctx context.Context, runID string) (Overview, error)
- func (s Service) ReadHandler() http.Handler
- func (s Service) Save(ctx context.Context, runID string, src Source, records []Record, ...) (SaveResult, error)
- func (s Service) SessionGraphScope(ctx context.Context, run, harness, session string) (*provenance.GraphSessionScope, error)
- func (s Service) SessionRelations(ctx context.Context, opts SessionRelationOptions) (SessionRelationsPage, error)
- func (s Service) SnapshotFields(ctx context.Context, entry Entry) ([]SnapshotField, string, error)
- type SessionEnumerationOptions
- type SessionIdentity
- type SessionMetadata
- type SessionRef
- type SessionRelation
- type SessionRelationEvidence
- type SessionRelationOptions
- type SessionRelationsPage
- type SnapshotChange
- type SnapshotComparison
- type SnapshotField
- type SnapshotValue
- type Source
- type SourceCursor
- type Status
Constants ¶
const ( MaxDiscoveryFiles = 4096 MaxDiscoveryVisits = 20000 MaxDiscoveryBytes = 256 << 20 )
const ( CurrentExecution = "current_execution" PriorContext = "prior_context" )
const ( ParserVersion = "context-parser/v10" MaxInputBytes = 128 << 20 MaxLineBytes = 40 << 20 MaxRecords = 25000 )
const CapturePolicyVersion = "agentprovenance.context_capture/v1"
const SchemaVersion = "agentprovenance.agent_context/v1"
Variables ¶
var ErrHookCaptureLimit = errors.New("normalized hook exceeds capture limit")
var ErrInvalidArgument = errors.New("invalid context argument")
var ErrSessionEnumerationLimit = errors.New("session enumeration resource limit exceeded")
Functions ¶
func HookCaptureDiagnostic ¶ added in v0.10.0
HookCaptureDiagnostic contains only a fixed code; source input is never logged on malformed or oversized hooks. Parse records it as a collection failure.
func RetainHookEvent ¶ added in v0.10.0
func RetainHookEvent(data []byte, policy CapturePolicy) ([]byte, error)
RetainHookEvent applies the run's policy before the hook sidecar is written. Filtered rows carry omission metadata, never a reference to discarded bytes.
func ToolNodeID ¶
ToolNodeID namespaces a native call identity by run and actor. Transcript and hook channels can describe the same invocation, while separate runs cannot overwrite each other's graph nodes when a harness reuses a call ID.
Types ¶
type Candidate ¶
type Candidate struct {
Path string `json:"path"`
SessionID string `json:"session_id"`
ParentSessionID string `json:"parent_session_id,omitempty"`
AgentID string `json:"agent_id,omitempty"`
Workdir string `json:"workdir,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
ModifiedAt time.Time `json:"modified_at"`
Size int64 `json:"size"`
Cursor SourceCursor `json:"cursor"`
Issue string `json:"issue,omitempty"`
}
type CaptureOmission ¶ added in v0.10.0
type CapturePolicy ¶ added in v0.10.0
type CapturePolicy struct {
Version string `json:"version"`
Preset string `json:"preset"`
ToolResults bool `json:"tool_results"`
SourceRecords bool `json:"source_records"`
History bool `json:"history"`
Configuration bool `json:"configuration"`
Overrides map[string]bool `json:"overrides,omitempty"`
}
CapturePolicy governs additional context retention, independently of sensor, TLS and workspace snapshots. Once recorded, a run's policy is immutable.
func NewCapturePolicy ¶ added in v0.10.0
func NewCapturePolicy(preset string, toolResults *bool) (CapturePolicy, error)
type ContentRef ¶
type ContentRef struct {
Ref string `json:"ref,omitempty"`
Bytes *int64 `json:"bytes"`
SHA256 string `json:"sha256,omitempty"`
MediaType string `json:"media_type,omitempty"`
Redacted bool `json:"redacted"`
State string `json:"state"`
Reason string `json:"reason,omitempty"`
DigestScope string `json:"digest_scope,omitempty"`
}
type Counts ¶
type Counts struct {
Discovered *int64 `json:"discovered"`
Matched *int64 `json:"matched"`
Read *int64 `json:"read"`
Parsed *int64 `json:"parsed"`
Stored *int64 `json:"stored"`
Duplicates *int64 `json:"duplicates"`
Truncated *int64 `json:"truncated"`
Failed *int64 `json:"failed"`
Unrecognized *int64 `json:"unrecognized"`
Deferred *int64 `json:"deferred"`
}
Counts are observations over one processing range, not estimates of all activity. Nil means unknown; a successful empty scan can explicitly report 0.
type Coverage ¶
type Coverage struct {
SchemaVersion string `json:"schema_version"`
ID string `json:"id"`
RunID string `json:"run_id"`
Source Source `json:"source"`
Status Status `json:"status"`
ObservedAt string `json:"observed_at"`
LastSuccessAt string `json:"last_success_at,omitempty"`
StartedAt string `json:"started_at,omitempty"`
EndedAt string `json:"ended_at,omitempty"`
FirstLine int64 `json:"first_line,omitempty"`
LastLine int64 `json:"last_line,omitempty"`
Counts Counts `json:"counts"`
Issues []Issue `json:"issues"`
MissingFields []string `json:"missing_fields"`
ObjectHash string `json:"object_hash,omitempty"`
PriorContext *PriorRange `json:"prior_context,omitempty"`
CapturePolicy *CapturePolicy `json:"capture_policy,omitempty"`
Omissions []CaptureOmission `json:"omissions,omitempty"`
}
type DiscoverOptions ¶
type DiscoverOptions struct {
Harness string
Root string
// CatalogRoot optionally locates Codex state catalogs outside the scan root.
// No ambient home directory is consulted for explicitly acquired sources.
CatalogRoot string
Workdir string
SessionID string
// Snapshot captures a pre-execution cursor for candidates in this workdir.
Snapshot bool
}
type Entry ¶
type Entry struct {
SchemaVersion string `json:"schema_version"`
ID string `json:"id"`
RunID string `json:"run_id"`
Source Source `json:"source"`
SourceKey string `json:"source_key"`
Sequence int64 `json:"sequence"`
// SourceOrdinal is the normalized record's position within its physical
// source line. Zero means older evidence did not record that position.
SourceOrdinal int64 `json:"source_ordinal,omitempty"`
Kind string `json:"kind"`
Role string `json:"role,omitempty"`
AgentID string `json:"agent_id,omitempty"`
ToolCallID string `json:"tool_call_id,omitempty"`
ToolName string `json:"tool_name,omitempty"`
Status string `json:"status,omitempty"`
RecordedAt string `json:"recorded_at,omitempty"`
Content ContentRef `json:"content"`
RawContent ContentRef `json:"raw_content"`
// IntentContent is a derived, bounded model-message projection when the
// source record is deliberately not retained. It is never an original record.
IntentContent *ContentRef `json:"intent_content,omitempty"`
MissingFields []string `json:"missing_fields,omitempty"`
EvidenceRefs []string `json:"evidence_refs,omitempty"`
ObjectHash string `json:"object_hash,omitempty"`
CreatedAt string `json:"created_at,omitempty"`
ExecutionScope string `json:"execution_scope,omitempty"`
SessionMetadata *SessionMetadata `json:"session_metadata,omitempty"`
}
func (Entry) ContentReferences ¶ added in v0.10.0
func (e Entry) ContentReferences() []ContentRef
ContentReferences includes the derived intent source, when present. Callers must apply the same reading and sharing boundaries to it as to the raw row.
type EntryLinks ¶
type Inventory ¶
type Inventory struct {
Harness string `json:"harness"`
Root string `json:"root"`
CatalogRoot string `json:"catalog_root,omitempty"`
Candidates []Candidate `json:"candidates"`
Complete bool `json:"complete"`
Issues []Issue `json:"issues"`
}
Inventory contains identities and resume boundaries, never conversation text. An incomplete inventory cannot establish a unique automatic binding.
type Overview ¶
type Overview struct {
SchemaVersion string `json:"schema_version"`
RunID string `json:"run_id"`
Coverage []Coverage `json:"coverage"`
Messages *int64 `json:"messages"`
ToolCalls *int64 `json:"tool_calls"`
ToolResults *int64 `json:"tool_results"`
Snapshots *int64 `json:"snapshots"`
HasMoreSources bool `json:"has_more_sources"`
RuntimeCoverage observability.RuntimeCoverage `json:"runtime_coverage"`
CapturePolicy *CapturePolicy `json:"capture_policy,omitempty"`
CaptureSettings *observability.CaptureSettings `json:"capture_settings,omitempty"`
}
type PageOptions ¶
type ParseBudget ¶
ParseBudget bounds a sequence of source imports, including decompressed input and records that are later rejected or deduplicated. It is not concurrency-safe. A nil budget keeps the normal per-source limits; zero means exhausted.
type ParseOptions ¶
type ParseOptions struct {
Harness string
Path string
SessionID string
ParentSessionID string
AgentID string
Binding string
BindingEvidence []string
// AfterLine is a physical source cursor captured before a resumed execution.
// Earlier records are retained as prior context, never current execution.
AfterLine int64
Cursor *SourceCursor
Budget *ParseBudget
}
type PriorRange ¶
type PriorRange struct {
FirstLine int64 `json:"first_line"`
LastLine int64 `json:"last_line"`
StartedAt string `json:"started_at,omitempty"`
EndedAt string `json:"ended_at,omitempty"`
Counts Counts `json:"counts"`
MissingFields []string `json:"missing_fields"`
}
PriorRange describes the retained prefix separately from the current range. These records supply historical context, not evidence of execution in this run.
type Record ¶
type Record struct {
Key string
Sequence int64
SourceOrdinal int64
Kind string
Role string
AgentID string
ToolCallID string
ToolName string
Status string
RecordedAt string
Body *string
RawBody *string
MediaType string
MissingReason string
MissingFields []string
ExecutionScope string
// Parsed values are position-specific, including unknown values. Nil lets
// explicit Record callers use the source defaults.
Workdir *string
ApplicationVersion *string
// contains filtered or unexported fields
}
Record is a parser's transient output. Body never appears in the entry index or diagnostics: it is redacted and stored as bounded content-addressed chunks.
type SaveResult ¶
type SelectOptions ¶
type SelectedSource ¶
type SelectedSource struct {
Candidate
AfterLine int64 `json:"after_line"`
Binding string `json:"binding"`
BindingEvidence []string `json:"binding_evidence"`
ResumeCursor *SourceCursor `json:"resume_cursor,omitempty"`
}
func (SelectedSource) ParseOptions ¶
func (s SelectedSource) ParseOptions(harness string) ParseOptions
type Selection ¶
type Selection struct {
Sources []SelectedSource `json:"sources"`
Status Status `json:"status"`
Issues []Issue `json:"issues"`
}
func SelectSources ¶
func SelectSources(ctx context.Context, before, after Inventory, opts SelectOptions) Selection
SelectSources never chooses by mtime. Without a native identity, only one new root session with matching cwd and a source timestamp in the run window can match. A resumed session requires an explicit identity and a verified prefix.
type Service ¶
type Service struct {
DB *sql.DB
Paths store.Paths
CapturePolicy *CapturePolicy
}
func (Service) CompareSnapshots ¶
func (Service) EnsureCapturePolicy ¶ added in v0.10.0
EnsureCapturePolicy fixes the policy before launch creates hook logs or starts a workload. Save uses the same transaction helper for later imports.
func (Service) EnumerateSessions ¶ added in v0.10.0
func (s Service) EnumerateSessions(ctx context.Context, opts SessionEnumerationOptions) ([]SessionIdentity, error)
EnumerateSessions walks latest source reports in bounded keyset pages and verifies their immutable identities before deduplicating native sessions. Export callers must use their already frozen (and selected) database for this entire operation and for all subsequent indexes. Overview is only a summary. Errors return no partial catalog, including cancellation and budget exhaustion.
func (Service) ImportFile ¶
func (s Service) ImportFile(ctx context.Context, runID string, opts ParseOptions) (SaveResult, error)
func (Service) Links ¶
Links exposes existing graph relationships, never a new matching inference. A result without a projected call deliberately has no execution destination.
func (Service) ReadHandler ¶
ReadHandler is shared by the local dashboard and daemon. It only resolves registered objects within the requested run; it never accepts disk paths.
func (Service) Save ¶
func (s Service) Save(ctx context.Context, runID string, src Source, records []Record, report Coverage) (SaveResult, error)
Save atomically appends immutable record revisions and a processing report. Re-reading unchanged records is a no-op; a late result or changed snapshot is a new revision. Neither a retry nor a parse failure deletes earlier evidence.
func (Service) SessionGraphScope ¶ added in v0.10.0
func (s Service) SessionGraphScope(ctx context.Context, run, harness, session string) (*provenance.GraphSessionScope, error)
SessionGraphScope selects existing tool and event links. A shared process, working directory or cgroup never expands the session's event membership.
func (Service) SessionRelations ¶ added in v0.10.0
func (s Service) SessionRelations(ctx context.Context, opts SessionRelationOptions) (SessionRelationsPage, error)
SessionRelations is a read projection over immutable source records. It never changes run membership or treats shared resources as a session relationship.
func (Service) SnapshotFields ¶ added in v0.10.0
SnapshotFields projects a saved configuration into bounded, typed values. It does not merge sessions, select an effective policy, or open live files.
type SessionEnumerationOptions ¶ added in v0.10.0
type SessionIdentity ¶ added in v0.10.0
type SessionIdentity struct {
Harness string `json:"harness"`
SessionID string `json:"session_id"`
}
SessionIdentity is namespaced by harness, not by source/channel or run.
type SessionMetadata ¶ added in v0.10.0
type SessionMetadata struct {
ForkedFromID string `json:"forked_from_id,omitempty"`
}
SessionMetadata preserves native relationship facts independently of optional configuration bodies. A non-nil empty value records an observed absence of a fork.
type SessionRef ¶ added in v0.10.0
type SessionRelation ¶ added in v0.10.0
type SessionRelation struct {
ID string `json:"id"`
Kind string `json:"kind"`
From SessionRef `json:"from"`
To SessionRef `json:"to"`
Evidence []SessionRelationEvidence `json:"evidence"`
Issues []string `json:"issues,omitempty"`
}
type SessionRelationEvidence ¶ added in v0.10.0
type SessionRelationOptions ¶ added in v0.10.0
type SessionRelationsPage ¶ added in v0.10.0
type SessionRelationsPage struct {
SchemaVersion string `json:"schema_version"`
Subject SessionRef `json:"subject"`
Relations []SessionRelation `json:"relations"`
HasMore bool `json:"has_more"`
NextCursor string `json:"next_cursor,omitempty"`
Limit int `json:"limit"`
Limited bool `json:"limited"`
Issues []string `json:"issues"`
}
type SnapshotChange ¶
type SnapshotChange struct {
Path string `json:"path"`
Before SnapshotValue `json:"before"`
After SnapshotValue `json:"after"`
}
type SnapshotComparison ¶
type SnapshotComparison struct {
SchemaVersion string `json:"schema_version"`
Scope string `json:"scope"`
Status string `json:"status"`
Left Entry `json:"left"`
Right Entry `json:"right"`
Changes []SnapshotChange `json:"changes"`
HasMore bool `json:"has_more"`
Reason string `json:"reason,omitempty"`
}
SnapshotComparison compares recorded values, not effective permissions. An absent field means "not recorded here", never allowed, denied, or revoked.
type SnapshotField ¶ added in v0.10.0
type SnapshotField struct {
Path string `json:"path"`
Value SnapshotValue `json:"value"`
}
type SnapshotValue ¶
type Source ¶
type Source struct {
ID string `json:"id"`
Harness string `json:"harness"`
Channel string `json:"channel,omitempty"`
SessionID string `json:"session_id"`
ParentSessionID string `json:"parent_session_id,omitempty"`
AgentID string `json:"agent_id,omitempty"`
Path string `json:"path,omitempty"`
ParserVersion string `json:"parser_version"`
ApplicationVersion string `json:"application_version,omitempty"`
FormatVersion string `json:"format_version,omitempty"`
Binding string `json:"binding"`
BindingEvidence []string `json:"binding_evidence,omitempty"`
Workdir string `json:"workdir,omitempty"`
}
type SourceCursor ¶
type SourceCursor struct {
Lines int64 `json:"lines"`
Bytes int64 `json:"bytes"`
SHA256 string `json:"sha256"`
Valid bool `json:"valid"`
}
A cursor hashes complete decompressed physical lines. A growing final line stays outside the prefix and is retried, including in concatenated zstd files.
Source Files
¶
- capture.go
- catalog_codex.go
- compare.go
- compression.go
- configuration.go
- discovery.go
- generation_deepseek.go
- hook_capture.go
- http.go
- links.go
- model.go
- parse.go
- parse_budget.go
- parse_claude.go
- parse_codex.go
- parse_compat.go
- parse_deepseek.go
- query.go
- session_enumeration.go
- session_relations.go
- session_scope.go
- source_objects.go
- store.go