dream

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package dream is the nightly consolidation pass — logos sleeping on the day.

It runs in two phases. NREM (cheap, deterministic, first) stabilises the memory store: it replays the day's salient experience, extracts gist from recurring structure, and downscales the whole field so only what is reinforced stays prominent. REM (expensive, model-driven, last) recombines the cleaned store into candidate connections — the engine behind the mirror.

The house rules hold throughout. Compute, then narrate: what to replay, downscale, and bridge is chosen by arithmetic; the model only phrases a connection. Propose, don't assert: NREM's structural maintenance is the same deterministic upkeep already trusted to run headless, but every REM inference is an Insight in this queue — never a silent write.

Index

Constants

View Source
const (
	PhaseNREM = "nrem"
	PhaseREM  = "rem"
	PhaseAll  = "all"
)

Phase selects which half of the night to run. NREM stabilises; REM recombines. REM always runs after NREM so it works over the cleaned, compressed store.

View Source
const DownscaleFactor = 0.98

DownscaleFactor is the nightly homeostatic multiplier (the SHY hypothesis: sleep globally renormalises weights). Small, so the field re-normalises gently and reinforced memories stand out by relative height without anything meaningful vanishing between one night and the next.

View Source
const InsightsFile = "dream-insights.md"

InsightsFile is the queue's name at the vault root.

View Source
const MaxInsights = 3

MaxInsights caps how many connections a single night may propose. A review queue flooded with speculation is a queue the user stops reading, and an unread queue is the same as no confirmation gate at all.

View Source
const QueueSchema = `` /* 435-byte string literal not displayed */
View Source
const SalienceFloor = 0.05

SalienceFloor stops downscaling from ever erasing a memory outright.

Variables

This section is empty.

Functions

func Accept

func Accept(db *sql.DB, p *provider.Provider, embedModel string, in Insight) (bool, error)

Accept turns a reviewed insight into a memory. It enters the store at the "dream" confidence (0.5) and a modest salience: a hypothesis that must earn belief through corroboration on the ordinary reinforcement path, never one that outranks a fact the user stated. The insight itself is marked accepted, not deleted, so the decision stays on the record.

func Enqueue

func Enqueue(db *sql.DB, in *Insight) error

func Import

func Import(db *sql.DB, dir string) (int, error)

Import restores dreamed insights from the vault, and is what makes deleting the cache survivable for them.

dir is the caller's rather than vaultFor's: `logos index` imports a vault it has not bound to a store yet.

Returns how many insights it had to put back — a row already in the cache was never lost and is not announced as recovered.

func InitQueue

func InitQueue(db *sql.DB) error

func InsightsPath

func InsightsPath(dir string) string

InsightsPath is where the queue lives inside dir. Exported because index.Sync has to know which file in the vault root it must not index.

func PendingCount

func PendingCount(db *sql.DB) (int, error)

func SetStatus

func SetStatus(db *sql.DB, id int64, s Status) error

SetStatus records the decision. Rejections are kept, not deleted: "you dreamed this and I said no" is the signal for tuning what the pass proposes later.

func SetVault

func SetVault(db *sql.DB, dir string)

SetVault binds a database to the vault its insights belong in. An empty dir unbinds it, which is what a cache-only store wants and what index.Close does so a closed handle leaves nothing behind.

Types

type Insight

type Insight struct {
	ID        int64
	Kind      Kind
	Text      string // the synthesised observation, one or two sentences
	EndpointA int64  // memory id it bridges from
	EndpointB int64  // memory id it bridges to
	Conf      float64
	Model     string
	Created   int64
	Status    Status
}

Insight is a REM proposal awaiting review. It is modelled on rollup.Proposal, but its terminal is the memory store, not the vault: accepting one stores a low-confidence memory that then lives or fades in the ordinary decay loop.

Both endpoints are mandatory and enforced at write time — this is the hallucination filter. A connection that cannot name the two real memories it bridges is a fabrication with good manners, and it must be impossible to queue.

func Get

func Get(db *sql.DB, id int64) (Insight, error)

Get returns a single insight by id.

func List

func List(db *sql.DB, status Status) ([]Insight, error)

func (*Insight) Validate

func (in *Insight) Validate() error

Validate enforces the invariants that make the queue trustworthy — checked on every insert, never trusted from the model.

type Kind

type Kind string

Kind is what a dreamed insight would become if accepted.

const (
	// Connection: a non-obvious link between two things the assistant already
	// knows — a shared theme, a tension, or an idea one suggests about the other.
	Connection Kind = "connection"
	// Thread: a candidate line of work the day's activity hints at, synthesised
	// from more than one memory.
	Thread Kind = "thread"
)

type Result

type Result struct {
	Date       string
	Replayed   int  // memories re-affirmed by consolidation (merged + superseded)
	Merged     int  // near-duplicates folded
	Superseded int  // stale facts replaced
	Downscaled int  // memories touched by the homeostatic pass
	Insights   int  // REM connections proposed for review
	REMSkipped bool // REM could not run (no reasoning model)
	// ReplaySkipped is true when consolidation could not run because no model
	// was reachable. Distinct from "nothing to consolidate", which is what a
	// swallowed error used to look like.
	ReplaySkipped bool
}

Result is what a night's sleep did (or, under dry run, would do).

func Run

func Run(db *sql.DB, vaultDir string, rt *router.Router, date time.Time, phase string, dryRun bool) (Result, error)

Run executes the consolidation pass for one day. NREM's structural edits are deterministic maintenance and run headless; REM's inferences become Insights in the review queue. Under dryRun nothing is written — the Result reports what the pass would change, so a night of sleep is auditable before it is trusted.

date and embedModel are accepted for compatibility with a per-night result (the Date field) and were formerly also used to scope gist extraction over a window of captured events; that step was cut in 0.3.0 along with the rest of ambient capture, so both nrem and rem now work purely over the memory store.

type Status

type Status string
const (
	Pending  Status = "pending"
	Accepted Status = "accepted"
	Rejected Status = "rejected"
)

Jump to

Keyboard shortcuts

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