Documentation
¶
Overview ¶
Package focus is memcode's COGNITIVE / attention axis — what the human is attending to — the complement of package room (the emotional / interaction axis). Doctrine: memcode models attention moving through commitments. room models how the interaction is going; focus models what the human is attending to; objectives model commitments that became durable.
FocusState is a pure DERIVED projection over the episodic log + objectives: rebuildable, deletable, no canonical store. A focus strand is a transient candidate objective; an objective is a strand that crossed a commitment threshold, so the durable layer here is just the active objectives — no parallel store.
Phase 0 derives transitions DETERMINISTICALLY from signals already in the log (commits → milestone; terse "done/forget/park" language → status changes; a new substantive ask → the prior strand pauses). Fuzzy strand identity/merge is left to a later model-judged pass — the same determinism-for-facts, judgment-for-judgment rule used elsewhere. It is intentionally simple; we dogfood whether it's useful before investing in clustering.
Index ¶
Constants ¶
const ( BurstSessions = 5 BurstGap = 48 * time.Hour BurstPerSession = 120 )
The orientation window FromLog reduces: the most recent prior session ALWAYS loads (that's "where you left off", however old); older sessions join only while consecutive gaps stay within BurstGap (one stretch of work), capped at BurstSessions. PerSession caps IO, not meaning.
const SourceMemcode = "memcode"
SourceMemcode is the provenance tag for turns derived from memcode's own session log — the only Source that exists today, and the one every existing caller gets for free via Reduce/FromLog.
Variables ¶
This section is empty.
Functions ¶
func Render ¶
Render formats the state as the cold-start orientation block. It leads with the UNFINISHED threads (numbered, newest first, with provenance notes) and closes with reconciliation semantics: verify against git, then account for every thread — resume, done, or dropped — never silently omit one. Redaction is the caller's responsibility — titles come from user text. Empty when nothing to show.
Types ¶
type FileClaim ¶ added in v0.46.0
FileClaim is an unverified claim, from a transcript, that a file was written/edited to a specific resulting content.
type State ¶
type State struct {
Current string // the strand the user is on right now ("" if none active)
Open []Strand // active, not yet the current focus
Paused []Strand // superseded, aborted, or explicitly parked — UNFINISHED work
Completed []Strand // reached a commit/verify or an explicit "done"
Dropped []Strand // explicitly abandoned
Decisions []string // durable commitments (active objectives)
// Elided counts strands cut by the per-bucket cap (paused+completed+dropped).
// Rendered as PROSE ("…and N older threads"), never as a fake list entry —
// a "(+1 more)" thread the model must "account for" is noise, not memory.
Elided int
// contains filtered or unexported fields
}
State is the reduced attention snapshot. Buckets hold strands, most recent FIRST.
func FromLog ¶
func FromLog(root, excludeSessionID string, objs []objectives.Objective) State
FromLog computes the live FocusState for a repo: the current work burst of prior sessions plus the current session's records, reduced as ONE chronological stream. The single source of truth for orientation (runtime.focusNow) and the memcode{session} tool — one window, one reducer.
func Reduce ¶
func Reduce(recs []sessionlog.Record, objs []objectives.Objective) State
Reduce projects episodic records (chronological) plus objectives into a FocusState. It is a thin, 100%-backward-compatible wrapper over ReduceTurns for memcode's own session log — existing callers are unaffected by the more general multi-source reducer underneath.
func ReduceTurns ¶ added in v0.46.0
func ReduceTurns(turns []Turn, objs []objectives.Objective) State
ReduceTurns is Reduce's general form: it reduces a chronological stream of Turns from ANY mix of sources into a FocusState. This is the actual cross-source "consolidated memory" — one reduction over a provenance-tagged turn stream, reusing the one piece of strand-detection logic that's genuinely source-agnostic.
func (State) Lines ¶
Lines renders the state as plain "label: a · b" facts (no header) — the form to FEED a synthesis prompt (/predict) as grounding. Empty when there's nothing to surface.
func (State) Unfinished ¶
Unfinished returns the open work, newest first: the (prior-session) current strand, then open, then paused. This is the list a status answer must account for — the digest and memcode{session} both render it.
type Status ¶
type Status string
Status is a soft attention state. `Dropped` is used ONLY on a clear forget/abandon signal — humans say "skip" temporarily far more often than they truly abandon.
type Strand ¶
type Strand struct {
Title string
Full string // the complete user message (untruncated) — act on THIS, not Title
Note string
Session string // source session id, so the thread names where to recover full context
// Sources names the distinct provenance(s) (e.g. "memcode", "claude-code")
// whose turns built this strand — a thread can legitimately be touched by
// more than one tool. Always ["memcode"] for a strand reduced from
// memcode's own session log alone.
Sources []string
}
Strand is one thread of work: the user's ask, its FULL verbatim text, an optional provenance note ("plan cancelled mid-flight — never executed"), and the session it came from. Title is a display summary (first line, capped); Full is the complete request the agent must act on — the two diverge for a long ask, and acting on the truncated Title instead of Full is exactly the bug that amputated a multi-part spec.
type Turn ¶ added in v0.46.0
type Turn struct {
TS time.Time
Kind string // one of the sessionlog.Kind* values — the shared vocabulary
Text string
Tool string
Input string
Decision string
HeadSHA string
Slug string
Entities []string
Source string // "memcode", "claude-code", "codex", … — provenance, never dropped
SourceSessionID string // the session id WITHIN that source
// FileClaim is set when this turn claims a file was written/edited with
// specific resulting content. It is an UNVERIFIED claim — strong evidence
// of intent/attempt, weaker evidence of what actually survived to disk —
// until something checks it against git/filesystem state.
FileClaim *FileClaim
}
Turn is one unit of a cross-source turn stream — the shared representation that any source (memcode's own session log, or an external tool's transcript) converts into before reduction. ReduceTurns treats every Turn identically regardless of Source: a human saying "thanks" is glue whether they said it to memcode or to another tool. Provenance (Source, SourceSessionID) rides along as a plain field — never conflated with memcode's own session identity, never used to rank one source over another.
func TurnsFromRecords ¶ added in v0.46.0
func TurnsFromRecords(recs []sessionlog.Record) []Turn
TurnsFromRecords is fromRecords, exported for package observe's Layer-B merge: it needs memcode's own native turns in the SAME shared representation an external source's turns convert into, before handing the merged, chronological stream to ReduceTurns. No behavior beyond fromRecords — same mapping, same Source tag.