Skip to main content

Class: MarkdownImporter

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:133

Imports Markdown files from a directory into a Brain.

Usage:

const importer = new MarkdownImporter(brain);
const result = await importer.import('/path/to/vault');
console.log(result.imported, result.skipped);

Extended by​

Constructors​

Constructor​

new MarkdownImporter(brain): MarkdownImporter

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:137

Parameters​

brain​

Brain

The target Brain to import into.

Returns​

MarkdownImporter

Properties​

brain​

protected readonly brain: Brain

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:137

The target Brain to import into.

Methods​

addNoteToHeldTrace()​

protected addNoteToHeldTrace(_trace, _body, _result): Promise<void>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:227

Add to a trace what its own note holds beyond the trace, once the import has found the note to be that trace's own note; the note then counts as skipped. The base implementation adds nothing: a Markdown note holds only the trace's text. ObsidianImporter adds the tags of the note's tag line and the links of its Related: list that the trace does not hold yet.

Parameters​

_trace​

HeldTrace

The trace the note is the note of.

_body​

string

The note's body, without its leading and trailing whitespace.

_result​

ImportResult

Mutable result accumulator.

Returns​

Promise<void>


holdsTraceText()​

protected holdsTraceText(text, body, _db?): boolean | Promise<boolean>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:212

Whether a note's body holds a trace's text: the text without its leading and trailing whitespace, which the import takes off a body, is the body, each line break in both read as \n (see withLfLineBreaks). A note whose front-matter id names a trace of its scope and scope id that it holds is that trace's own note, and so its duplicate, also when the trace's text begins or ends with whitespace. ObsidianImporter also reads past the tag line and the links ObsidianExporter writes after the text, and may read the brain's graph to do so, through db, so an override may answer with a promise.

Parameters​

text​

string

The text of the trace the note's id names.

body​

string

The note's body, without its leading and trailing whitespace.

_db?​

Pick<Brain, "all">

What a read of the brain goes through: the note's transaction, which holds a connection of the brain's own, so a read through the brain would wait for another (a Postgres pool of one waits for good).

Returns​

boolean | Promise<boolean>

true when the note holds the trace's text, or a promise of the answer.


import()​

import(sourceDir, options?): Promise<ImportResult>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:152

Recursively walk sourceDir, parse every .md file, and insert traces.

Non-Markdown files are silently ignored. Files that fail to parse are recorded in result.errors and processing continues.

Parameters​

sourceDir​

string

Directory to recursively scan for .md files.

options?​

Pick<ImportOptions, "dedup">

Returns​

Promise<ImportResult>

ImportResult with counts of imported, skipped, and errored items.


postProcess()​

protected postProcess(_filePath, _frontmatter, _body, _result, _traceId): Promise<void>

Defined in: packages/agentos/src/cognition/memory/io/MarkdownImporter.ts:185

Post-process a parsed file before it is inserted into the database.

The base implementation is a no-op. ObsidianImporter overrides this to extract [[wikilinks]] and #tags.

Parameters​

_filePath​

string

Absolute path of the source file.

_frontmatter​

TraceFrontmatter

Parsed front-matter data.

_body​

string

Markdown body content.

_result​

ImportResult

Mutable result accumulator.

_traceId​

string

The ID assigned (or taken from front-matter) for this trace.

Returns​

Promise<void>