Skip to content

Store layout and path algebra

$MEMHTML_ROOT/ a git repo, one global memory store
projects/<workspace-slug>/ a workspace is a directory; there is no workspaces table
projects/<slug>/tasks/ task files: one named segment, not a fifth bucket
areas/<area>/ areas/arcs/ areas/inbox/ areas/inbox/tasks/
resources/<topic>/ resources/people/<person>.html
archive/<YYYY>[.<n>]/<original-path> soft-evicted, path-preserving
.memhtml/index.db gitignored, rebuildable
.memhtml/state.db gitignored, NOT rebuildable from git
.memhtml/state/access.jsonl COMMITTED sidecar: a copy of state.access
.memhtml/sessions/<id>.json gitignored: one session's overlay log
.memhtml/snapshots/<sha>.arrow gitignored: the head at one commit, newest four kept
.memhtml/vectors/ gitignored: the head's vector cache
.memhtml/head.sock gitignored: a running head server's socket
.memhtml/checkout.lock present only while a writer holds the checkout
.memhtml/sleep/ the sleep pipeline's reports, removed in 0.16; init still creates it empty
memhtml.config.json COMMITTED store policy; never a memory
sitemap.xml, index.html generated by publish, committed

The top level is fixed at four buckets: projects, areas, resources, and archive (packages/contracts/src/types.ts::PARA_BUCKETS). That scheme is borrowed from the PARA method of organizing personal files, and this page uses the name PARA for it. archive is a bucket rather than a status value because the path itself is what records the state.

A workspace is a directory and nothing else. There is no workspaces table, so creating a workspace costs a mkdir inside a commit, and deleting one is a git mv.

placementFor (packages/contracts/src/paths.ts) applies five rules in order:

  1. an explicit valid path;
  2. an arc goes to areas/arcs;
  3. a task goes to projects/<slug>/tasks, or to areas/inbox/tasks when it names no workspace, before the topic rule runs;
  4. a named workspace goes to projects/<slug>;
  5. a semantic, procedural, or precedent memory with a primary tag goes to resources/<tag>, unless that tag slugs to people.

Anything remaining goes to areas/inbox. The function always returns a directory rooted in a bucket, so the write path never guesses twice and never fails to place a memory.

No rule routes into resources/people. A person: entity says who a record is about, and the record still files by its workspace or topic. A person record is at resources/people/<person>.html only because its writer named that explicit path. In a session outside the curate scope that path is reserved (packages/session/src/validate.ts::isReservedPath). Until 2026-09-28 a person: entity on a semantic memory routed it there, so an agent’s fact that mentioned a colleague was refused as a reserved path.

Rule 1 reads “an explicit valid path”, and the validity clause is where a caller gets a choice. An explicit path is unusable when it is not rooted in a bucket, does not end in .html, or carries a . or .. segment. The write ignores such a path and places the memory by rules 2 to 5 or the inbox fallback. It succeeds at a path the caller did not name, and the response reports that other path as the outcome. memoryPathViolation (packages/contracts/src/paths.ts) is the rule and its explanation in one function, and isValidMemoryPath is the same question asked as a boolean, so a refusal’s reason cannot name a clause the predicate does not check.

--strict-path on memhtml write, strict_path on memory_write and on each memory_write_batch op, and strict_path on a memhtml apply line make that re-derivation a refusal instead. The refusal is ERR_INVALID_MEMORY, naming the clause the path broke, with nothing written, staged, or committed. It is opt-in because the lenient branch is shipped behavior. It matters to a caller that computes its paths, which is how a consumer models its own document types on top of the open axes. The refusal is strictPathRefusal in @memhtml/store, and it runs ahead of both the render gate and the dedupe question in writeMemory, in each batch op’s validation, and in correctMemory. That ordering is the contract. A strict check placed after the dedupe question would answer “deduped, at some other path” for content the store already holds and “refused” for content it does not. Identical malformed input would then report two different outcomes, and only one of them would mention the path.

The refusal is ERR_INVALID_MEMORY rather than ERR_WRITE_CONFLICT, which is what an occupied explicit path earns. That error names the blob that occupies the path, and its published recovery is memhtml read <path> then memhtml correct <path>. Neither call repairs a path no file can occupy. An unusable path is malformed caller input, which is what InvalidMemory is for and what every other decode on the write path already uses.

memoryPathFor (packages/contracts/src/paths.ts::memoryPathFor) adds the filename. It date-prefixes an episodic entry, because time is part of that memory’s identity. Every other type is timeless, so it takes the bare slug of its title.

archivePathFor (packages/contracts/src/paths.ts::archivePathFor) mirrors the whole original path beneath archive/<YYYY>/, and originalPathFor (packages/contracts/src/paths.ts::originalPathFor) strips exactly one such prefix. Stripping one rather than all of them keeps it a left inverse for every path, a nested archive path included. git log --follow reads through the move, and diff -M reports a rename instead of a delete plus an add, below 100 percent similarity because the archive stamps edit the file’s head. No memory is removed from the repository.

A test pins the property: originalPathFor(archivePathFor(p, y)) === p for every generated path. memhtml doctor --fix uses the inverse to repair a link whose target was archived. It takes the indexed archive paths that map back to the target and points the link at the newest one (apps/cli/src/repair.ts::archivedFormOf). When no archive path maps back, it drops the link. No code reads a rename-similarity score.

A path archived again while its year’s slot is held takes the next generation of that year, archive/<YYYY>.2/<original-path>, then .3, and so on, so an archive never writes over an earlier one. archiveSlotFor (packages/contracts/src/paths.ts::archiveSlotFor) names the first free generation. Every writer that archives takes that slot, and the session validator refuses any other. originalPathFor reads a generation slot back to the same original path, so the property holds for every generation: originalPathFor(archivePathFor(p, y, n)) === p.

Figure 1 draws the mapping as a ladder rather than as a round trip. The bottom rung is a nested path, an archive path archived again. From it the inverse climbs one rung and reaches an archive path, which is what “exactly one prefix” means. No write makes a nested path. A path archived a second time takes another slot for the same original path, and from that slot the inverse returns the original path in one step.

Three paths stacked vertically as the rungs of a ladder: notes/x.html, then archive/2026/notes/x.html, then archive/2027/archive/2026/notes/x.html. A solid arrow labelled archivePathFor descends one rung at a time. A dashed arrow labelled originalPathFor ascends one rung at a time and never more than one, so from the bottom rung it reaches the middle one rather than the top.

Figure 1: archivePathFor descends one rung and originalPathFor climbs exactly one. An archive descends once, as a move inside a commit that diff -M reports as a rename, and no writer archives a path already under archive/. Ascending is a pure function of the path, which is why those edges are dashed. Because each application moves one rung, the inverse stays a left inverse even on a nested path, and a single return edge to the live path would describe that wrongly.

A usable memory path carries no . or .. segment (packages/contracts/src/paths.ts::memoryPathViolation). A write re-derives a path that carries one, or refuses it under --strict-path. memhtml archive and memhtml correct refuse one as their source (packages/contracts/src/paths.ts::activeRecordPathViolation). So a write, a correction, or an archive never creates or moves a file through such a path.

The path is the id of a memory, and there is no separate uuid anywhere in the system (packages/contracts/src/types.ts::MemoryPath). files.path is the primary key of the index’s central table. That key moves when a memory is archived or moved, so every child table declares ON UPDATE CASCADE alongside ON DELETE CASCADE.

An href value in the HTML plane carries the same path with a leading slash. That leading slash is a document-reference form, converted at the HTML boundary and never stored (packages/contracts/src/types.ts::MemoryPath, packages/index/src/project.ts::authoredEdgesFor).

5. A citation resolves forward, or pins a commit

Section titled “5. A citation resolves forward, or pins a commit”

A correction never edits a file in place. memhtml correct and memory_correct write the corrected fact at another path and move the original into its archive slot, archive/<YYYY>/ or archive/<YYYY>.<n>/. The path is the id, so anything outside the store that recorded the old path, such as a receipt, a report, or another agent’s note, now names a path the tree does not hold. Two reads answer that, and they answer different questions.

memhtml resolve <path> walks forward (apps/cli/src/operations.ts::resolveMemory). It follows two mechanisms: an authored supersedes link, and the archive move recorded by origin_path. A record can also move while it stays live, through a session move operation or a git mv to another live path. The walk does not follow that move, because the index keeps no record of the path the record left, so that path resolves as unindexed.

A correction points its supersedes link at the target’s archive path, so a cited pre-archive path has no inbound edge and only the archive mapping knows where its bytes went. The walk therefore reads the mapping for a path absent from the index, and the edge for a path present in it.

Every node the walk reports is named by the path that holds that memory now. A supersedes link is an element inside a file, so archiving that file carries the link with it. When two corrections land at two new paths, the chain reads cited → archive(cited) → archive(middle) → live, and the middle’s own live path appears nowhere.

The answer’s stopReason is the field that decides whether to cite, and only live means yes. archived is a memory that was evicted rather than corrected, so nothing supersedes it. unindexed means the index holds no such path and no archive path that maps back to it. The path may never have been a memory, its record may have moved while live, or the index may not yet describe the commit that holds it. indexedCommit names the commit the index does describe.

cycle and hop_limit are the two abnormal endings. A cycle is two memories each claiming to supersede the other, an authoring defect the walk refuses to resolve. hop_limit means the walk took 16 hops (apps/cli/src/operations.ts::RESOLVE_MAX_HOPS), so the answer is where it stopped rather than the end of the chain.

Nothing is fabricated under any of the five stop reasons. A resolver that answered “not found” for the four other than live would collapse an eviction, a moved record, a stale index, and a corpus defect into one word.

Forward resolution cannot answer one thing: whether a live path still holds the bytes you cited. A path that an archive or a correction left empty can be written again, by a new write or by a later correction with the same title. That path is then live at zero hops, while the record behind it states a different fact.

The pinned citation answers that question. memhtml://at/{commit}/{path} is an MCP resource that reads the git object at a named commit rather than the working tree (apps/mcp/src/resources.ts::PinnedResource). A commit sha is immutable, so those bytes cannot move. HEAD and a branch name such as main are refused, because a URI whose target can move is not a citation. memory_resolve publishes such a URI ready-made as pinned_uri for every answer but unindexed.

6. memhtml init converges on one end state

Section titled “6. memhtml init converges on one end state”

memhtml init (packages/store/src/layout.ts::initRepo) creates the store, and no other command makes the root a git repository. Each step asks the repository what is already true, so the command reaches the same end state from an empty directory, from a live repository, and from one an interrupted run left half-staged.

It re-sets merge.ours.driver on every run (packages/store/src/layout.ts::initRepo), because that config is per-clone and the .gitattributes a fresh clone inherits does nothing without it. It sets merge.directoryRenames=false beside it, so a merge never reads an archive move that took a directory’s last file as that directory’s rename and carries another clone’s new record there into archive/. Those two together are what make the generated artifacts, the per-directory index.html and the root sitemap.xml, resolvable by regenerating them instead of by editing them.