{"modulePath":"github.com/memcode-ai/memcode","version":"v0.56.16","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package focus\n\nPackage 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.\n\nFocusState 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.\n\nPhase 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.\n\n## Constants\n\n```go\nconst (\n\tBurstSessions   = 5\n\tBurstGap        = 48 * time.Hour\n\tBurstPerSession = 120\n)\n```\nThe 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.\n\n```go\nconst SourceMemcode = \"memcode\"\n```\nSourceMemcode 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.\n\n## Functions\n\n```go\nfunc Render(s State) string\n```\nRender 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.\n\n## Types\n\n```go\ntype FileClaim struct {\n\tPath        string\n\tClaimedHash string\n\tClaimedAt   time.Time\n}\n```\nFileClaim is an unverified claim, from a transcript, that a file was written/edited to a specific resulting content.\n\n```go\ntype State struct {\n\tCurrent   string   // the strand the user is on right now (\"\" if none active)\n\tOpen      []Strand // active, not yet the current focus\n\tPaused    []Strand // superseded, aborted, or explicitly parked — UNFINISHED work\n\tCompleted []Strand // reached a commit/verify or an explicit \"done\"\n\tDropped   []Strand // explicitly abandoned\n\tDecisions []string // durable commitments (active objectives)\n\n\t// Elided counts strands cut by the per-bucket cap (paused+completed+dropped).\n\t// Rendered as PROSE (\"…and N older threads\"), never as a fake list entry —\n\t// a \"(+1 more)\" thread the model must \"account for\" is noise, not memory.\n\tElided int\n\t// contains filtered or unexported fields\n}\n```\nState is the reduced attention snapshot. Buckets hold strands, most recent FIRST.\n\n```go\nfunc FromLog(root, excludeSessionID string, objs []objectives.Objective) State\n```\nFromLog 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.\n\n```go\nfunc Reduce(recs []sessionlog.Record, objs []objectives.Objective) State\n```\nReduce 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.\n\n```go\nfunc ReduceTurns(turns []Turn, objs []objectives.Objective) State\n```\nReduceTurns 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.\n\n```go\nfunc (s State) Empty() bool\n```\nEmpty reports whether there's nothing worth surfacing.\n\n```go\nfunc (s State) Lines() []string\n```\nLines 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.\n\n```go\nfunc (s State) Unfinished() []Strand\n```\nUnfinished 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.\n\n```go\ntype Status string\n```\nStatus 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.\n\n```go\nconst (\n\tActive    Status = \"active\"\n\tPaused    Status = \"paused\"\n\tParked    Status = \"parked\"\n\tCompleted Status = \"completed\"\n\tDropped   Status = \"dropped\"\n)\n```\n\n```go\ntype Strand struct {\n\tTitle   string\n\tFull    string // the complete user message (untruncated) — act on THIS, not Title\n\tNote    string\n\tSession string // source session id, so the thread names where to recover full context\n\n\t// Sources names the distinct provenance(s) (e.g. \"memcode\", \"claude-code\")\n\t// whose turns built this strand — a thread can legitimately be touched by\n\t// more than one tool. Always [\"memcode\"] for a strand reduced from\n\t// memcode's own session log alone.\n\tSources []string\n}\n```\nStrand 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.\n\n```go\nfunc (st Strand) AskLine() string\n```\nAskLine renders a thread as the VERBATIM ask (full when present, else title) plus its note and source session — the form external callers (memcode{session} OPEN THREADS) show so the model acts on the whole request, not a paraphrase.\n\n```go\ntype Turn struct {\n\tTS       time.Time\n\tKind     string // one of the sessionlog.Kind* values — the shared vocabulary\n\tText     string\n\tTool     string\n\tInput    string\n\tDecision string\n\tHeadSHA  string\n\tSlug     string\n\tEntities []string\n\n\tSource          string // \"memcode\", \"claude-code\", \"codex\", … — provenance, never dropped\n\tSourceSessionID string // the session id WITHIN that source\n\n\t// FileClaim is set when this turn claims a file was written/edited with\n\t// specific resulting content. It is an UNVERIFIED claim — strong evidence\n\t// of intent/attempt, weaker evidence of what actually survived to disk —\n\t// until something checks it against git/filesystem state.\n\tFileClaim *FileClaim\n}\n```\nTurn 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.\n\n```go\nfunc TurnsFromRecords(recs []sessionlog.Record) []Turn\n```\nTurnsFromRecords 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.\n\n","path":"github.com/memcode-ai/memcode/internal/agent/focus","name":"focus","synopsis":"Package focus is memcode's COGNITIVE / attention axis — what the human is attending to — the complement of package room (the emotional / interaction axis).","isRedistributable":true}
