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
- Variables
- func Scrub(s string) (string, bool)
- type Envelope
- type Highlight
- type Item
- type Materials
- type Omitted
- type OneShot
- type OneShotRequest
- type Options
- type Outcome
- type Result
- type RunOptions
- type RunStore
- type Service
- type Source
- type SynthConfig
- type SynthResult
- type Synthesizer
- type Window
Constants ¶
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.
const DayLayout = "2006-01-02"
DayLayout is the format of a business day ("2026-10-28").
const ResultSchemaV1 = "daily-memory-synthesis.v1"
ResultSchemaV1 is the schema tag of the model's answer and of the stored result_json.
const SchemaV1 = "daily-memory-materials.v1"
Variables ¶
var ( ErrAgent = errors.New("agent call failed") ErrOutputFormat = errors.New("invalid output") ErrUnsafeInput = errors.New("unsafe input") ErrUnsafeOutput = errors.New("unsafe output") )
Reasons a synthesis fails; each is the stable prefix of the error kept on the run record.
Functions ¶
Types ¶
type Highlight ¶ added in v0.207.0
type Highlight struct {
Text string `json:"text"`
SourceRefs []string `json:"source_refs,omitempty"`
}
Highlight is one concrete development with the source refs it rests on.
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.
type Materials ¶
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.
type OneShot ¶ added in v0.207.0
type OneShot interface {
Run(ctx context.Context, r OneShotRequest) (string, error)
}
OneShot runs a model call and returns the agent's stdout.
type OneShotRequest ¶ added in v0.207.0
type OneShotRequest struct {
ProjectKey string
Agent string
Args []string
Prompt string
Title string
Timeout time.Duration
// MaxOutputBytes is how much stdout the adapter reads at most (+1 so an oversized
// answer is detected rather than silently cut).
MaxOutputBytes int
// Origin is the ceiling owner the call is submitted under ("" = none).
Origin string
}
OneShotRequest is one read-only, tool-less model call. The adapter that implements OneShot fixes the safety shape (read-only, no tools, no rules, hidden internal job); the caller only supplies the text and the operator's model arguments.
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 Result ¶ added in v0.207.0
type Result struct {
Schema string `json:"schema"`
Summary string `json:"summary"`
Highlights []Highlight `json:"highlights"`
OpenQuestions []string `json:"open_questions"`
}
Result is the validated, normalised answer stored in memory_synthesis_runs.result_json. Unknown fields a model may add are dropped, never stored.
func ParseResult ¶ added in v0.207.0
ParseResult extracts the single JSON object of a model answer (a markdown fence or text around it is tolerated) and validates it strictly: schema tag, bounded non-empty summary, bounded lists, and every cited source ref must be in `allowed`.
type RunOptions ¶ added in v0.207.0
type RunOptions struct {
Project string
Day string
CreatedBy string
// Force runs the synthesizer even when a succeeded record with the same input digest
// exists (the old record is retired as skipped once the new run succeeds). It never
// bypasses a live run of the same project and day.
Force bool
}
RunOptions is the input of RunWith.
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
Prepare collects, scrubs and bounds the materials of one project day without touching the store.
type Source ¶
Source is a read-only structured material adapter. Adapters must not return transcripts, prompts, argv, environment values, or attachments.
type SynthConfig ¶ added in v0.207.0
type SynthConfig struct {
Agent string
Model string
Args []string
// Timeout bounds one call (memory.synthesis.timeout).
Timeout time.Duration
// MaxOutputBytes bounds the model answer (memory.synthesis.max_output_bytes).
MaxOutputBytes int
// Origin is the ceiling owner of the model call: the caller that asked for the run.
Origin string
// Lang is the project language the prompt (and so the summary) is written in.
Lang i18n.Lang
}
SynthConfig is what a synthesizer needs from memory.synthesis (already resolved).
type SynthResult ¶ added in v0.205.0
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.
func NewSynthesizer ¶ added in v0.207.0
func NewSynthesizer(o OneShot, c SynthConfig) Synthesizer
NewSynthesizer builds the model-backed Synthesizer: it renders the prompt from the already scrubbed and bounded envelope, makes one read-only call and validates the answer. It never sees anything but Materials (the output of Build), and re-checks the serialised envelope for secret shapes so a caller that bypassed Build cannot leak them to a model.
type Window ¶ added in v0.205.0
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
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.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package engine assembles one explicit daily memory synthesis run: it reads the live memory.synthesis configuration, builds the material sources and the model-backed synthesizer, and drives memorysynthesis.Service.
|
Package engine assembles one explicit daily memory synthesis run: it reads the live memory.synthesis configuration, builds the material sources and the model-backed synthesizer, and drives memorysynthesis.Service. |
|
Package sources holds the read-only material adapters of daily memory synthesis.
|
Package sources holds the read-only material adapters of daily memory synthesis. |