Cloud The core runtime is open source and free. TekMemo Cloud (hosted sync, managed MCP, team features) is in early access. Join the waitlist →
Skip to content

Core Primitives

The core primitives module of @tekbreed/tekmemo defines the memory model, document types, validation, and canonical file path conventions. These are the building blocks used by the Tekmemo class and its strategies.

Import

ts
import {
  bootstrapMemoryStore,
  readCoreMemory,
  writeCoreMemory,
  readNotesMemory,
  appendTimestampedNote,
  readManifest,
  searchMemoryText,
  chunkText,
  InMemoryMemoryStore,
} from "@tekbreed/tekmemo";

Core concepts

  • Core Memory: The stable project briefing.
  • Notes: Durable, timestamped records of decisions and facts.
  • Events: An append-only ledger of all memory changes.
  • Chunks: Indexed fragments for fast semantic search.

Quick start with Tekmemo

The Tekmemo class wraps most core primitives behind its namespaces. Use Tekmemo as your primary API and reach for these helpers only when you need low-level control:

ts
import { Tekmemo } from "@tekbreed/tekmemo";

const memo = new Tekmemo({ rootDir: "./.tekmemo", projectId: "my-app" });

// Preferred — use Tekmemo namespaces
const core = await memo.core.read();
await memo.notes.record({ content: "Ship feature X", kind: "decision" });

API Reference

Memory Store Helpers

HelperPurpose
bootstrapMemoryStore(store, options)Initializes a memory store with default files and directories.
chunkText(text, options)Splits text into semantic chunks for indexing.

Document Helpers

HelperPurpose
readCoreMemory(store)Reads and parses the core.md document.
writeCoreMemory(store, content)Validates and writes core.md.
readNotesMemory(store)Reads and parses the notes.md document.
appendTimestampedNote(store, note)Appends a TimestampedNote (e.g., { kind, content, timestamp }) to notes.
readManifest(store)Reads the manifest.json file.
searchMemoryText(options)Performs a simple keyword-based search on a text string.

Error Classes

ClassCodePurpose
TekMemoErrorbaseBase error for all core runtime errors.
MemoryPathErrorTEKMEMO_INVALID_PATHInvalid memory path (bad format, traversal attempt).
MemoryNotFoundErrorTEKMEMO_NOT_FOUNDRequested memory file does not exist.
MemoryValidationErrorTEKMEMO_VALIDATION_ERRORMemory data fails validation.
MemoryParseErrorTEKMEMO_PARSE_ERRORMemory data cannot be parsed.
MemoryCommandErrorTEKMEMO_COMMAND_ERRORMemory command is invalid or cannot execute.
MemoryStoreErrorTEKMEMO_STORE_ERRORMemory store operation fails.
ts
import { isTekMemoError, MemoryNotFoundError } from "@tekbreed/tekmemo";

try {
  await store.read(path);
} catch (error) {
  if (isTekMemoError(error)) {
    console.error(`[${error.code}] ${error.message}`);
  }
}

Direct usage (advanced)

For operations outside of Tekmemo:

ts
import { InMemoryMemoryStore, readCoreMemory, writeCoreMemory } from "@tekbreed/tekmemo";

const store = new InMemoryMemoryStore();
await writeCoreMemory(store, "# Project Overview\n\nThis is a TekMemo project.");
const core = await readCoreMemory(store);
console.log(core.content);

Released under the MIT License.