MarkdownDataStore

MarkdownDataStore stores named records as Markdown files whose data is divided into numbered level-three sections. It is useful when people must be able to inspect and edit persisted session or profile data without a database client.

Example record

The following calls create data/sessions/session-1.md and append a second history entry:

const store = new MarkdownDataStore({ dataDir: './data' });

await store.updateFile('sessions', 'session-1', {
    Profile: '- Developer',
    History: '- **User**: Document the request flow'
});

await store.appendToFile('sessions', 'session-1', {
    sections: {
        History: '- **Agent**: Added the MainAgent diagram'
    }
});

The resulting file remains normal Markdown:

### 1. Profile
- Developer

### 2. History
- **User**: Document the request flow
- **Agent**: Added the MainAgent diagram

Main operations

OperationBehavior
listFiles(type)Lists Markdown record names at the root or within a validated type directory.
getFile(type, name, selectors)Returns all sections and raw Markdown, or selected sections by name or one-based index.
getSectionMap()Returns section content keyed by section name.
replaceFile()Replaces the complete ordered section set.
appendToFile()Appends content to matching sections and can deduplicate normalized lines.
updateFile()Appends to existing sections and creates missing sections.
deleteFile()Deletes selected sections and renumbers the remainder, or deletes the complete file.
parseList(), parseDialogue(), parseKeyValue()Convert supported Markdown shapes to arrays or records; matching render methods produce canonical Markdown.

Safety and scope

The constructor requires dataDir. Type and file-name normalization prevent traversal outside that directory. Empty section content is normalized to *None*. The store does not interpret the business meaning of a section and does not provide cross-file transactions.