Skip to main content

Class: MarkdownExporter

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:122

Exports memory traces as Markdown files with YAML front-matter.

Usage:

const exporter = new MarkdownExporter(brain);
await exporter.export('/path/to/vault');

Extended by​

Constructors​

Constructor​

new MarkdownExporter(brain): MarkdownExporter

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:126

Parameters​

brain​

Brain

The Brain instance to read from.

Returns​

MarkdownExporter

Properties​

brain​

protected readonly brain: Brain

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:126

The Brain instance to read from.

Methods​

buildFileContent()​

protected buildFileContent(trace): string

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:287

Build the Markdown content for a single trace.

Subclasses (e.g. ObsidianExporter) override this to inject wiki-links and #tag decorations into the body.

Parameters​

trace​

TraceRow

Parsed trace row from the database.

Returns​

string

Full Markdown file content (front-matter + body).


export()​

export(outputDir, _options?): Promise<ExportResult>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:154

Export the brain's live memory traces as .md files into outputDir. Another brain's traces in the same database are not read.

Directories are created on demand, one name at a time. A trace is not written, and is reported in the result, when its scope, type or id is not a safe file or folder name, when its file would lie outside outputDir, when a folder or file in its place under outputDir is a symbolic link or its file has a second name (a hard link), when something other than a regular file holds its file's place (a folder, a named pipe, a socket, a device), or when an older trace's file is the same file, where names ignore case or by the file system's own reckoning. Every other trace is written. At most MAX_OPEN_TRACE_FILES files are open at once.

Parameters​

outputDir​

string

Root directory to write the Markdown vault into.

_options?​

ExportOptions

Optional export configuration (currently unused but accepted for API consistency with other exporters).

Returns​

Promise<ExportResult>

The traces left out, with the reason for each.

Throws​

The first error met opening or writing a file for a reason other than the refusals above, such as a full disk, once every other trace has been tried.


frontMatterOf()​

protected frontMatterOf(trace, tags): Record<string, unknown>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:314

The front-matter fields of a trace's file, which MarkdownImporter reads back: its id, type, scope, strength, tags and creation time, and its scope id as scopeId when the trace is filed under one. A trace filed under '' writes no scopeId, and its import files it under ''. A trace of a Brain that holds the encoded scope-id form writes scopeIdForm: encoded, so an import takes its scope id as it is written. A trace a second user filed on another user's session writes that user's id as turnUserId, so its import files it as that user's trace, which a delete of the user's traces finds.

Parameters​

trace​

TraceRow

The trace row.

tags​

string[]

The trace's tags, parsed.

Returns​

Record<string, unknown>


traceRelativePath()​

protected traceRelativePath(trace): string

Defined in: packages/agentos/src/cognition/memory/io/MarkdownExporter.ts:341

Determine the relative file path for a trace within the output directory.

Default: {scope}/{type}/{id}.md. Each of the three must be a safe file or folder name (see pathNameProblem), or the trace is refused. Whatever a subclass returns, the export writes the file only when its resolved path lies inside the output directory.

Parameters​

trace​

TraceRow

The trace row.

Returns​

string

Relative path string (no leading slash).

Throws​

When the trace's scope, type or id is not a safe name; the export reports such a trace in its result instead of writing it.