session

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package session is part of the GoFastr harness.

See docs/harness-architecture.md for the architecture this package implements.

Package session implements the SQLite append-only event log and associated retention/redaction/ledger machinery per § Persistence.

At-rest encryption is on the v0.2 roadmap (OPS-SQLITE-VACUUM / OPS-KEY-ROTATION); v0.1 stores unencrypted but applies the redaction middleware on the write path so secrets never land on disk.

Index

Constants

View Source
const (
	ErrUnknownSession = ErrSession("session: unknown session")
	ErrSchemaMismatch = ErrSession("session: schema version mismatch")
	ErrOrphanIntents  = ErrSession("session: tool intents without outcomes (orphans)")
)

Specific errors.

View Source
const PragmaWAL = "PRAGMA journal_mode = WAL"

Sentinel for placing the events table in WAL mode for crash safety. Applied at Open() time, separately from Schema (PRAGMAs can't go inside a transaction with DDL).

View Source
const Schema = `` /* 1005-byte string literal not displayed */

Schema is the v1 DDL. Migrations live as additional .sql files in session/sqlite/migrations/ when v2+ ships; v0.1 only needs v1.

View Source
const SchemaVersion = 1

Standard SQL schema. Exposed for tests + migrations. Bump SchemaVersion when changing.

Variables

This section is empty.

Functions

func EncodeEvent

func EncodeEvent(env control.EventEnvelope) []byte

EncodeEvent is a helper for tests/in-memory stores: serializes the envelope's payload to a raw JSON message.

Types

type ErrSession

type ErrSession string

ErrSession is the root of session-package errors.

func (ErrSession) Error

func (e ErrSession) Error() string

type ExportBundle

type ExportBundle struct {
	Store   Store
	Session ids.SessionID
	Profile string
	Model   string
	Level   RedactLevel
	OutPath string
}

ExportBundle writes a zip archive containing:

  • bundle.json — manifest (session ID, profile, version, redact level)
  • events.jsonl — one canonical event envelope per line
  • redactions.txt — only at RedactMaintainer; counts per pattern
  • meta.json — extra metadata (profile, model, turn count)

func (*ExportBundle) Write

func (e *ExportBundle) Write(ctx context.Context) (string, error)

Write produces the bundle on disk. Returns the bundle path.

type PastSession

type PastSession struct {
	SessionID    ids.SessionID `json:"sessionId"`
	FirstSeenAt  time.Time     `json:"firstSeenAt"`
	LastSeenAt   time.Time     `json:"lastSeenAt"`
	EventCount   int64         `json:"eventCount"`
	FirstMessage string        `json:"firstMessage,omitempty"` // first user-turn text, truncated
}

PastSession is a single past-session summary row returned by Store.ListPastSessions. Used to populate the "Sessions" sidebar and the REST /v1/sessions?past=true endpoint.

type RedactLevel

type RedactLevel int

RedactLevel controls how aggressively the export bundle redacts.

const (
	// RedactStrict — drop full content; emit kinds + timestamps only.
	RedactStrict RedactLevel = iota
	// RedactStandard — apply the same redactors that ran on write.
	// (The on-disk events already passed through these; this level
	// re-applies them to be safe in case a custom redactor was
	// disabled.)
	RedactStandard
	// RedactMaintainer — run a deeper-pass detector on top of the
	// stored content and include a redaction report in the bundle.
	RedactMaintainer
)

type Store

type Store interface {
	// AppendEvent persists one envelope. Called by an event-bus
	// subscriber on every Publish.
	AppendEvent(ctx context.Context, env control.EventEnvelope) error

	// EventsSince returns events with id > since for the given
	// session, in ID order. Used by stream-resume across all
	// transports.
	EventsSince(ctx context.Context, session ids.SessionID, since uint64, limit int) ([]control.EventEnvelope, error)

	// ListPastSessions returns a summary row per distinct session in
	// the event log, ordered newest-last-seen first. limit ≤ 0 means
	// unbounded.
	ListPastSessions(ctx context.Context, limit int) ([]PastSession, error)

	// RecordToolIntent writes a tool_call_intents row before the
	// tool spawns. For mutating tools, the implementation MUST fsync
	// before returning.
	RecordToolIntent(ctx context.Context, intent ToolIntent) error

	// RecordToolOutcome writes a tool_call_outcomes row after the
	// tool returns. fsync for mutating tools.
	RecordToolOutcome(ctx context.Context, outcome ToolOutcome) error

	// OrphanIntents returns intent rows with no matching outcome —
	// used on resume to surface tool calls that started before a
	// crash and need user disposition.
	OrphanIntents(ctx context.Context, session ids.SessionID) ([]ToolIntent, error)

	// ApplyRetention drops content from events older than ttl,
	// leaving metadata-only rows. Called by a daily scheduled task.
	ApplyRetention(ctx context.Context, ttl time.Duration) (rowsAffected int64, err error)

	// Close releases resources.
	Close() error
}

Store is the durable session storage. Implementations: sqlite (v0.1).

type ToolIntent

type ToolIntent struct {
	CallID    ids.CallID
	LogID     ids.LogID
	Tool      string
	ArgsHash  string // sha256 of args
	Mutating  bool
	StartedAt time.Time
}

ToolIntent is one row in the intent ledger.

type ToolOutcome

type ToolOutcome struct {
	CallID      ids.CallID
	Outcome     string // "ok" | "error" | "cancelled" | "timeout"
	CompletedAt time.Time
	ResultRef   string // pointer into events table (event ID encoded)
}

ToolOutcome is one row in the outcome ledger.

Directories

Path Synopsis
Package sqlite is part of the GoFastr harness.
Package sqlite is part of the GoFastr harness.

Jump to

Keyboard shortcuts

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