memorysynthesis

package
v0.205.0 Latest Latest
Warning

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

Go to latest
Published: Oct 31, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package memorysynthesis contains the bounded, privacy-filtered material envelope used by daily memory synthesis. The envelope (materials.go) has no database or agent dependency: callers provide already structured source items and Build performs the common ordering, de-duplication, secret scrubbing, budget enforcement, and digest calculation. service.go coordinates one run record through the jobstore; concrete material adapters live in the sources subpackage.

Index

Constants

View Source
const (
	OutcomeSucceeded = "succeeded"
	OutcomeFailed    = "failed"
	// OutcomeReused: a succeeded run with the same input digest exists; only last_checked_at moved.
	OutcomeReused = "reused"
	// OutcomeRunning: another run of the same project and day is in flight.
	OutcomeRunning = "running"
	// OutcomeEmpty: the window has no material, so no record was created.
	OutcomeEmpty = "empty"
)

Outcome states reported by Service.Run.

View Source
const DayLayout = "2006-01-02"

DayLayout is the format of a business day ("2026-10-28").

View Source
const SchemaV1 = "daily-memory-materials.v1"

Variables

This section is empty.

Functions

func Scrub added in v0.205.0

func Scrub(s string) (string, bool)

Scrub replaces every secret-shaped fragment of s with [redacted] and reports whether it changed anything. Callers must scrub BEFORE truncating: a cut through the middle of a secret would otherwise leave an unrecognisable (and still sensitive) prefix behind.

Types

type Envelope

type Envelope struct {
	Schema   string  `json:"schema"`
	Project  string  `json:"project"`
	Day      string  `json:"day"`
	Timezone string  `json:"timezone"`
	Items    []Item  `json:"items"`
	Omitted  Omitted `json:"omitted"`
}

type Item

type Item struct {
	ID          string   `json:"id"`
	Kind        string   `json:"kind"`
	OccurredAt  string   `json:"occurred_at,omitempty"`
	Title       string   `json:"title,omitempty"`
	Text        string   `json:"text,omitempty"`
	SourceRef   string   `json:"source_ref"`
	SourceRefs  []string `json:"source_refs,omitempty"`
	Sensitivity string   `json:"sensitivity,omitempty"`
}

Item is one allow-listed fact from a source adapter. Text is never treated as instructions.

func Collect

func Collect(ctx context.Context, project, day string, sources ...Source) ([]Item, error)

type Materials

type Materials struct {
	Envelope
	InputDigest string `json:"input_digest"`
}

Materials is the persisted-safe result of preparing an envelope. The digest covers the canonical envelope, including omission counts, and is therefore stable for identical input.

func Build

func Build(project, day, timezone string, input []Item, opts Options) (Materials, error)

Build prepares source items into the versioned envelope. It is deterministic: items are ordered by occurrence and source, duplicate source refs/text are merged, and all limits are applied before hashing. The returned bytes never contain the original value of a scrubbed secret.

type Omitted

type Omitted struct {
	Items   int      `json:"items,omitempty"`
	Bytes   int      `json:"bytes,omitempty"`
	Reasons []string `json:"reasons,omitempty"`
}

type Options

type Options struct {
	MaxInputBytes   int
	MaxItemsPerKind int
	MaxRunesPerText int
}

type Outcome added in v0.205.0

type Outcome struct {
	State string
	Run   jobstore.MemorySynthesisRun
}

Outcome is the result of one Service.Run call. Run is zero for OutcomeEmpty.

type RunStore added in v0.205.0

type RunStore interface {
	BeginMemorySynthesisIfChanged(jobstore.MemorySynthesisBegin) (jobstore.MemorySynthesisRun, jobstore.MemorySynthesisBeginOutcome, error)
	FinishMemorySynthesisRun(id string, f jobstore.MemorySynthesisFinish) (jobstore.MemorySynthesisRun, error)
}

RunStore is the persistence the coordinator needs; *jobstore.Store implements it.

type Service added in v0.205.0

type Service struct {
	Store   RunStore
	Sources []Source
	Options Options
	Synth   Synthesizer
	// Loc is the server time zone used for the business-day window (default time.Local).
	Loc      *time.Location
	Lookback time.Duration
	// Timeout bounds a run; a running record older than this is treated as stale.
	Timeout time.Duration
	// KeepSnapshot stores the scrubbed envelope on the run record (keep_material_snapshot).
	KeepSnapshot bool
	Now          func() time.Time
	NewID        func() string
}

Service coordinates material preparation and the run record. It owns no goroutines; callers (an explicit run command, later a scheduler) decide when to call Run.

func (*Service) Prepare added in v0.205.0

func (s *Service) Prepare(ctx context.Context, project, day string) (Materials, error)

Prepare collects, scrubs and bounds the materials of one project day without touching the store.

func (*Service) Run added in v0.205.0

func (s *Service) Run(ctx context.Context, project, day, createdBy string) (Outcome, error)

Run prepares the materials and drives one run record: unchanged input reuses the existing succeeded record, a live run for the same day is left alone, and otherwise the synthesizer runs once and the record is finished as succeeded or failed.

type Source

type Source interface {
	Collect(context.Context, string, string) ([]Item, error)
}

Source is a read-only structured material adapter. Adapters must not return transcripts, prompts, argv, environment values, or attachments.

type SynthResult added in v0.205.0

type SynthResult struct {
	Agent      string
	Model      string
	ResultJSON string
}

SynthResult is what a synthesizer hands back. P1 never calls a model: the function is a seam that tests (and later phases) fill in.

type Synthesizer added in v0.205.0

type Synthesizer func(context.Context, Materials) (SynthResult, error)

Synthesizer turns prepared (already scrubbed and bounded) materials into a result.

type Window added in v0.205.0

type Window struct {
	Day   string
	Start time.Time
	End   time.Time
}

Window is the half-open interval [Start, End) of one business day in the server's time zone, optionally widened backwards by a longer lookback. A source keeps an event when Contains(unix) is true, so the day boundaries never double count or drop an event.

func DayWindow added in v0.205.0

func DayWindow(day string, loc *time.Location, lookback time.Duration) (Window, error)

DayWindow computes the window of `day` in loc. The window always ends at the next local midnight and starts at the day's own midnight; a lookback longer than 24h only moves the start earlier (End - lookback), a shorter or zero one keeps the plain day. Computing the midnights from calendar dates (not by adding 24h) keeps DST days 23 / 25 hours long.

func (Window) Contains added in v0.205.0

func (w Window) Contains(unix int64) bool

Contains reports whether the unix-second timestamp falls inside [Start, End).

func (Window) Timezone added in v0.205.0

func (w Window) Timezone() string

Timezone is the UTC offset label written into the envelope ("+08:00").

Directories

Path Synopsis
Package sources holds the read-only material adapters of daily memory synthesis.
Package sources holds the read-only material adapters of daily memory synthesis.

Jump to

Keyboard shortcuts

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