Skip to main content

Function: ensureMemoryDir()

ensureMemoryDir(workspaceDir): string

Defined in: packages/agentos/src/cognition/substrate/memory/wiki/migrateMemoryMd.ts:46

Guarantee a memory/ directory exists in the workspace and return its path. Idempotent: what is already there is left untouched.

  • memory/ and memory/.meta/ are made when missing.
  • A missing memory/index.md is seeded from MEMORY.md when the workspace holds one, and is otherwise a stub. MEMORY.md is left on disk as a fallback.
  • A missing memory/.meta/index.json starts an empty page index.

Never modifies or deletes MEMORY.md.

The workspace's own folder, memory/ and memory/.meta/ are made one name at a time below the folder that holds the workspace, and index.md and .meta/index.json only in a place that nothing holds, so nothing is written through a symbolic link and no file already there is opened. MEMORY.md is read never through a link and never waiting. When a link, or anything other than a folder, holds the place of the workspace's folder, memory/ or .meta/, nothing is made in them; when a link or anything other than a regular file holds the place of index.md, .meta/index.json or MEMORY.md, that place is left as it is and the file that would come from it is not made. Each of those writes one warning, and the path is returned all the same.

Parameters​

workspaceDir​

string

The per-agent workspace directory. It may not be a link; the folder that holds it may.

Returns​

string

The memory/ directory's path: memory joined to workspaceDir, absolute when workspaceDir is.