kernel.store

Four places a mind keeps things beyond the world. They differ in what losing them costs.

HoldsLose it and
store.sessioneverything that happened this session — read-onlycan't; it's the record
storea private cache, keyed by namerebuild it from the session
knowledgereadable material, published with the agentreal data is lost
memorythe mind's own databases — what it learnedwhat it learned is lost
kernel.store.session.get(opts?: { after?: number }): readonly Entry[]
kernel.store.get(key: string): Promise<Value | null>
kernel.store.set(key: string, value: Value): Promise<void>

kernel.knowledge.list(opts?: { match?: string; limit?: number }): Promise<KnowledgeEntry[]>
kernel.knowledge.read(name: string): Promise<string>
kernel.knowledge.write(name: string, content: string): Promise<void>
kernel.knowledge.remove(name: string): Promise<void>

kernel.memory.connect(name: string): Connection

store.session — the record

Every entry this session, in order. Read-only, forever: a mind can't rewrite its history. Pass after to read only what's new since the last entry you saw.

let seen = 0
for (const entry of kernel.store.session.get({ after: seen })) {
    fold(entry)
    seen = entry.time.seq
}

store — a cache

Private to the mind, last write wins, atomic per key. get returns null when a key is absent or unreadable — either way, the fix is the same: rebuild it from the session. Deleting the cache is always safe.

await kernel.store.set("checkpoint", { seq: seen, summary: summary })
const saved = await kernel.store.get("checkpoint")

In TypeScript, keys are typed by declaring them once:

declare global {
    interface CognetStoreSchema {
        checkpoint: { seq: number; summary: string }
    }
}

knowledge — published material

Readable files the mind consults and maintains — notes, docs, data — published with the agent. Not a cache: writes are atomic, and reading a name that doesn't exist throws.

const found = await kernel.knowledge.list({ match: "deploy", limit: 40 })
const text = await kernel.knowledge.read("axon/deploy.md")
await kernel.knowledge.write("notes/incident.md", summary)

An entry has a name, a description ("" when none), its size, and a path to open it with. Names are identifiers, not paths — one that would escape the store throws. list is ordered by name; match filters on name and description.

The kernel has no search. How a mind recalls is part of the mind.

memory — the mind's databases

Says where a named database lives. The mind brings its own database engine and opens it there, usually from a plugin at boot.

const connection = kernel.memory.connect("long-term")
// { type: "sqlite", path } | { type: "remote", url, token? } | { type: "memory" }

Never rebuildable, never published. Write when the mind learns something — not on the way out.

Errors

ErrorWhen
KNOWLEDGE_NOT_FOUNDreading a name that doesn't exist
KNOWLEDGE_ESCAPEa name that would resolve outside the store
MEMORY_NAME_INVALIDa database name that isn't one lowercase word