MemoFSMemoFS
Core Runtime

Core Concepts

Architecture of canonical files, durability tiers, secret safety, code anchoring, memory decay, and knowledge graphs in MemoFS.

MemoFS organizes agent memory into structured, project-scoped layers. By separating memory by retrieval frequency and purpose, the system prevents context bloat while preserving long-term intelligence.

The 11 Canonical Files Layout

Inside your workspace root, MemoFS manages all memory state in the .memofs/ directory across 11 canonical files:

.memofs/
├── manifest.json              # [1]  Tracked memory assets & anchor hash cache
├── memory/
│   ├── core.md                # [2]  Core canonical rules & baseline facts
│   └── notes.md               # [3]  Archival timestamped memory notes
├── events/
│   ├── memory-events.jsonl    # [4]  Append-only memory write/event audit log
│   └── conversations.jsonl    # [5]  Chronological conversation interaction log
├── indexes/
│   ├── chunks.jsonl           # [6]  Chunked text fragments for lexical recall
│   └── embeddings.jsonl       # [7]  Persisted vector embeddings
├── graph/
│   ├── nodes.jsonl            # [8]  Entity nodes (concepts, tools, decisions)
│   └── edges.jsonl            # [9]  Relationship triples & dependencies
├── snapshots/
│   ├── snapshots.jsonl        # [10] Checkpoint index
│   └── <snapshot-id>.json     # Dynamic snapshot checkpoints
├── connectors.json            # [11] External source connectors (no secrets)
├── archive/
│   └── <memory-id>.json       # Full-fidelity cold-archived memory records
└── tmp/                       # Temporary workspace scratch directory

Canonical Files Reference

FileProtocol ConstantFormatAccess PatternPurpose
.memofs/manifest.jsonMANIFEST_PATHJSONRead at startupManifest of all canonical paths, metadata, and the anchor hash cache.
.memofs/memory/core.mdCORE_MEMORY_PATHMarkdownLoaded in prompt contextCondensed, high-signal project identity, baseline rules, and constraints.
.memofs/memory/notes.mdNOTES_MEMORY_PATHMarkdownAppended on demandLong-form timestamped notes, decisions, and architectural references.
.memofs/events/memory-events.jsonlMEMORY_EVENTS_PATHJSONLAppend-onlyAudit log of memory operations (memory.created, memory.archived, etc.).
.memofs/events/conversations.jsonlCONVERSATIONS_MEMORY_PATHJSONLAppend-onlyChronological agent conversation turns for historical reconstruction.
.memofs/indexes/chunks.jsonlCHUNKS_INDEX_PATHJSONLQueried on recallText chunks and lexical metadata for BM25 and fuzzy search.
.memofs/indexes/embeddings.jsonlEMBEDDINGS_INDEX_PATHJSONLQueried on recallPersisted vector embeddings for semantic similarity scoring.
.memofs/graph/nodes.jsonlGRAPH_NODES_PATHJSONLGraph queriesEntity vertices (features, symbols, concepts, decisions, actors).
.memofs/graph/edges.jsonlGRAPH_EDGES_PATHJSONLGraph queriesRelationship edges (depends_on, supersedes, uses, mentions).
.memofs/snapshots/snapshots.jsonlSNAPSHOTS_INDEX_PATHJSONLOn-demandMetadata index tracking available memory snapshots and checkpoints.
.memofs/connectors.jsonCONNECTORS_PATHJSONSync unitDeclarations for external data sources (GitHub, Notion). Uses secretRef only.

Durability Tiers (durable vs transient)

When a memory is written via memofs.writeMemory(), MemoFS classifies its durability tier:

  • durable: High-value facts, decisions, and constraints. Written to notes.md, recorded in memory-events.jsonl, and indexed into the recall index and knowledge graph so they steer future agent sessions.
  • transient: Scratchpad observations, temporary working state, or low-confidence guesses. Written to notes.md and memory-events.jsonl as an audit trail, but never indexed into recall or graph. This prevents scratch thoughts from polluting prompt context.

Classification Decision Rules

The classifier evaluates signals in strict priority order:

PriorityEvaluation ConditionResulting TierRationale
1input.tier explicitly provided"durable" or "transient"Explicit user or system override.
2confidence < 0.4 (TRANSIENT_CONFIDENCE_THRESHOLD)"transient"Low certainty should not steer future context.
3Trimmed content.length < 20 (TRANSIENT_CONTENT_MIN_LENGTH)"transient"Low-signal or incomplete scratchpad notes.
4kind is decision, constraint, goal, preference, or reference"durable"Durable knowledge categories.
5kind is note or summary"transient"Working state or ephemeral session notes.
6No kind specified (default)"durable"Default tier prevents accidental omission from recall.

Write Blocklist & Secret Safety

To prevent accidental leakage of credentials into syncable memory files, all writes through memofs.writeMemory(), memofs.core.update(), and memofs.agentfs.complete() pass through the Write Blocklist Gate (assertWriteAllowed):

  • Zero-Config, Always-On: The blocklist runs locally with zero external network dependencies.
  • Hard Rejection: Writes containing secret material throw MemoryWriteBlockedError immediately. Nothing is persisted.
  • Safe Redaction: Error messages and violation previews contain only redacted snippets (first 3 characters + + last character, e.g., sk-…z) — never full tokens.

Monitored Secret Patterns

The BLOCKLIST_RULES engine monitors five primary secret categories:

CategoryExample Identifier / PrefixRedacted Error Preview
Provider API KeysAWS (AKIA...), GitHub (ghp_...), OpenAI (sk-...), Google AI (AIza...), Slack (xox...), Stripe live (sk_live_...), MemoFS (tm_..., mfs_live_...)sk-…z, ghp…9
Private Key Blocks-----BEGIN PRIVATE KEY-----, RSA/EC PEM headers---…---
JSON Web Tokens (JWT)Base64url encoded triple tokens (eyJ...)eyJ…Q
Database Connection StringsEmbedded credentials (postgres://user:pass@host:5432/db)pos…db
Secret Variable Assignmentspassword=..., apiKey=..., secret: ... with high-entropy alphanumeric stringssec…e

Code Anchoring & Drift Detection

Memories can be bound to source code files using an AnchorRef. This binds the memory to a repository-relative path and the file's SHA-256 content hash computed at write time:

// Explicit anchor
await memofs.writeMemory({
  title: "Auth Token Rotation",
  content: "Tokens are verified in src/auth/verify.ts using asymmetric RSA256.",
  kind: "decision",
  anchor: {
    file: "src/auth/verify.ts",
    hash: "a3f5b8...",
    symbol: "src/auth/verify.ts#verifyToken", // Optional AST symbol path
  },
});

Alternatively, use the inline marker syntax in note content:

We enforce strict JWT validation. @anchor(file="src/auth/verify.ts", symbol="verifyToken")

Drift Detection at Recall Time

When memofs.recall() or memofs.context() executes:

  1. The recall engine consults the Anchor Hash Cache in .memofs/manifest.json (5-minute TTL with mtime invalidation).
  2. If the anchored source file was modified or deleted on disk, the recalled item is flagged with stale: true.
  3. Stale memories receive an automated 50% relevance score demotion (score *= 0.5).
  4. Stale items are still returned (rank-demoted rather than hidden) so agents are informed that the underlying code has drifted.

Memory Decay Floors

Knowledge naturally ages. To prevent obsolete decisions from being trusted indefinitely, MemoFS assigns kind-specific decay floors via EXPIRY_DAYS:

Memory KindExpiry FloorTypical Use Case
decision365 daysMajor architectural decisions and library selections.
constraint180 daysStrict project requirements and compliance rules.
reference180 daysLinks to external documentation, specs, and schemas.
goal120 daysMilestone objectives and sprint goals.
preference90 daysCode style, formatting, and tooling preferences.
summary60 daysHigh-level overviews of past refactors or discussions.
note30 daysWorking observations and implementation notes.

When a memory exceeds its expiry floor:

  • The item is flagged with unverified: true.
  • It receives a 40% score demotion (score *= 0.6 — milder than code drift).
  • Surfacing unverified memories signals to agents that human or automated re-verification is warranted.

Knowledge Graph & Fact Statuses

MemoFS includes an entity-relationship graph stored in graph/nodes.jsonl and graph/edges.jsonl.

Graph Fact Statuses

Every node and edge maintains a status:

StatusDescription
activeCurrent, verified canonical knowledge.
deprecatedSuperseded by a newer fact (kept for audit & history).
conflictedDirect contradiction detected.
staleAnchored code file has drifted or deleted.
unverifiedExceeded memory decay floor.
archivedMoved to cold storage in .memofs/archive/.
deletedMarked for deletion.

Orthogonal Flags

Nodes and edges also carry orthogonal boolean flags that do not override the primary status:

  • disputed: boolean: True when contested by conflicting facts.
  • stale: boolean: True when the bound code file has drifted.
  • unverified: boolean: True when fact age exceeds its kind-specific floor.

Memory Archive & Restore Lifecycle

Deprecated memories can be moved out of active memory into cold storage (.memofs/archive/<id>.json) using memofs.archiveDeprecated():

  1. active → deprecated: Consolidation identifies an edge A supersedes B and transitions fact B to deprecated.
  2. deprecated → archived: memofs.archiveDeprecated() moves the deprecated note to .memofs/archive/<id>.json and removes it from notes.md. Bound graph nodes transition to archived.
  3. archived → active: memofs.restoreMemory(id) reads the archive file, re-inserts the note into notes.md, reactivates the graph node, and deletes the archive JSON.

Progressive Context Retrieval

Instead of dumping the entire memory store into an LLM prompt, MemoFS uses a 4-Stage Strategist Retrieval Pipeline:

  1. Rewrite: Tokenizes the query, appends task-specific lexicon which defaults to general, and expands synonyms.
  2. Resolve: Looks up matching entities in the knowledge graph and computes active neighbor subgraphs.
  3. Filter: Applies code drift demotions, decay demotions, and suppresses retired entities.
  4. Budget: Slices sections according to target byte limits and weights, generating progressive expansion cursors:
export const SECTION_WEIGHTS = {
  recall: 3,
  entities: 2,
  recent: 1,
  notes: 1,
} as const;

On this page