observe

package
v0.47.4 Latest Latest
Warning

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

Go to latest
Published: Oct 14, 2026 License: MIT Imports: 15 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 observe is memcode's LAYER A for externally-sourced attention signals — Claude Code's and Codex's own local session transcripts — plus the LAYER-B merge that hands a cross-source turn stream to focus.ReduceTurns. It never writes to .memcode/sessions: that stays memcode's own, untouched, first-person episodic log. Its own on-disk format lives at .memcode/observe/<source>/<source-session-id>.jsonl — a bespoke minimal format, deliberately not sessionlog.Writer, so an external observation can never be mistaken for a native session on disk. Every record here is a CLAIM about what a tool did, not a verified fact (see FileClaim, and package acceptance's CorroborateClaim for checking one against git/filesystem state).

COST ARCHITECTURE (load-bearing, not incidental — see doctrine for the per-claim confidence rule this pairs with):

  • Zero LLM calls anywhere in this package. Ingestion (an importer's Import), normalization (into Record), and this file's merge are all deterministic parsing/bookkeeping — exactly how memcode treats its OWN session log today. There is no proactive summarization pass; if dogfooding later shows real semantic loss (architectural rationale, abandoned approaches that never produced a Turn-worthy event), that is a separate, explicitly-costed addition — not assumed here.
  • A Record is normalized to exactly what focus.ReduceTurns consumes, not a transcript copy: Text is capped at write time (maxText), well below a raw transcript turn. A 50k-token external session becomes a handful of capped records on disk, not a replica of the transcript.
  • Load is bounded on BOTH axes — maxFilesPerSource (recent sessions per source) and maxRecordsPerFile — so its parse cost stays flat as total ingested history grows to hundreds of sessions, mirroring sessionlog's own burst-window philosophy (see focus.BurstSessions).
  • What finally reaches a chat system prompt is bounded a second, independent time by focus.ReduceTurns' existing per-bucket/per-strand caps (maxPerBucket, maxFullAsk) — so the digest stays small REGARDLESS of how much external history exists, exactly as it already does for memcode's own history. Raw transcript text never reaches that far.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clip

func Clip(s string) string

Clip truncates s to maxText runes (rune-safe), for an importer to apply before ever writing a Record's Text to disk.

func HasAny

func HasAny(root string) bool

HasAny reports whether anything has ever been written under .memcode/observe/ — a cheap directory-presence check callers use to skip Load entirely (and keep paying zero cost) when no external source has ever been ingested, which is the common case today.

func Load

func Load(ctx context.Context, root, excludeSessionID string) []focus.Turn

Load merges memcode's own current work-burst turns (read via sessionlog, converted, NEVER written here) with every external source's recent observations under .memcode/observe/, sorted into one chronological stream — the actual cross-source "consolidated memory" ReduceTurns reduces. excludeSessionID is the live session, if any (mirrors focus.FromLog). Best-effort: a read failure on one file is logged and skipped, never fatal to the merge.

func ReadNewLines

func ReadNewLines(path string, fromOffset, maxBytes int64) (lines [][]byte, newOffset int64, err error)

ReadNewLines reads complete lines appended to path since fromOffset, up to maxBytes of NEW content, and returns the lines plus the offset to resume from. A trailing partial line (either genuinely still being written, or simply cut off by maxBytes) is left unconsumed — newOffset never advances past it — so it is re-read whole next time: incremental reading of an append-only JSONL log must never split a line across two syncs. Shared by every Adapter so this bookkeeping isn't duplicated per source.

func Sync

func Sync(ctx context.Context, root string, repoRoots []string, a Adapter, redact func(string) string) error

Sync does ONE bounded, deterministic ingestion pass for an adapter: for each file it discovers, reads only the bytes appended since that file's watermark (never the whole transcript again), redacts every Record's Text through redact BEFORE it ever touches disk, and appends to that session's observe log. Best-effort across files — one file's error is recorded but doesn't stop the rest; the watermark only advances for files that actually succeeded, so a failure is retried next time rather than silently skipped forever.

Types

type Adapter

type Adapter interface {
	Source() string
	Discover(repoRoots []string) []string
	Import(path string, fromOffset, maxBytes int64) (recs []Record, newOffset int64, err error)
}

Adapter is an external source's deterministic transcript reader — implemented by internal/importers/claudecode and internal/importers/codex. Discover finds candidate transcript files for the given repo roots (see gitlog.Roots); Import parses ONE file starting at a byte offset (incremental) up to maxBytes new bytes, returning the Records found and the offset to resume from next time. No LLM call anywhere in an Adapter — deterministic parsing only, matching how memcode treats its own session log.

type FileClaim

type FileClaim struct {
	Path        string    `json:"path"`
	ClaimedHash string    `json:"claimed_hash"`
	ClaimedAt   time.Time `json:"claimed_at,omitempty"`
}

FileClaim is an unverified claim, from a transcript, that a file was written/edited to a specific resulting content. Mirrors focus.FileClaim — kept as its own type here (the on-disk JSON shape) rather than embedding focus.FileClaim directly, so this package's wire format doesn't silently change if focus's in-memory type grows fields later.

type Record

type Record struct {
	TS        time.Time  `json:"ts"`
	Kind      string     `json:"kind"` // one of sessionlog.Kind* — the shared vocabulary
	Text      string     `json:"text,omitempty"`
	Tool      string     `json:"tool,omitempty"`
	Input     string     `json:"input,omitempty"`
	FileClaim *FileClaim `json:"file_claim,omitempty"`
}

Record is one externally-observed turn, normalized to exactly what focus.ReduceTurns consumes — never a transcript copy. Source and SourceSessionID are NOT persisted: the directory name IS the source, the filename IS the session id (same "the dir/file name is the identity, don't duplicate it" rule sessionlog.Record.SessionID already follows).

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer appends normalized Records for one external session to .memcode/observe/<source>/<sourceSessionID>.jsonl. A nil Writer is safe to Append/Close on, matching sessionlog.Writer's degrade-gracefully contract.

func Open

func Open(root, source, sourceSessionID string) (*Writer, error)

Open creates (or reopens, append-only) the on-disk log for one external source's session.

func (*Writer) Append

func (w *Writer) Append(r Record) error

Append writes one Record, clipping Text defensively even if the caller forgot to (see Clip). Safe on a nil Writer; safe under concurrent calls.

func (*Writer) Close

func (w *Writer) Close() error

Close flushes and closes the underlying file. Safe on a nil Writer.

Jump to

Keyboard shortcuts

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