Skip to main content

Class: ObsidianImporter

Defined in: packages/agentos/src/cognition/memory/io/ObsidianImporter.ts:191

Imports an Obsidian vault (directory of Markdown files) into a Brain.

Usage:

const importer = new ObsidianImporter(brain);
const result = await importer.import('/path/to/obsidian-vault');

Extends​

Constructors​

Constructor​

new ObsidianImporter(brain): ObsidianImporter

Defined in: packages/agentos/src/cognition/memory/io/ObsidianImporter.ts:206

Parameters​

brain​

Brain

The target Brain to import into.

Returns​

ObsidianImporter

Overrides​

MarkdownImporter.constructor

Properties​

brain​

protected readonly brain: Brain

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

The target Brain to import into.

Inherited from​

MarkdownImporter.brain

Methods​

addNoteToHeldTrace()​

protected addNoteToHeldTrace(trace, body, result): Promise<void>

Defined in: packages/agentos/src/cognition/memory/io/ObsidianImporter.ts:286

Add to a trace what its own note holds beyond the trace: the tags of the note's tag line the trace does not hold, a tag compared in the form the tag line writes it (whitespace as -), and links from the trace's node to the labels of the note's Related: list it does not link to, a link read as postProcess reads one. A note left as the export wrote it adds nothing to a trace that still holds the tags and links the export wrote; a tag or a link the trace lost after the export is added again.

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 (errors recorded here).

Returns​

Promise<void>

Overrides​

MarkdownImporter.addNoteToHeldTrace


holdsTraceText()​

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

Defined in: packages/agentos/src/cognition/memory/io/ObsidianImporter.ts:262

Whether a note's body holds a trace's text: the body is the text, as a Markdown note's is, or it opens with the text, without its leading and trailing whitespace, and holds after it, past whitespace, only what ObsidianExporter writes there: the tag line, the Related: list, or the tag line, a blank line and the list. Each link of the list is a line - [[label]], or runs over the line breaks of a label the brain's graph holds, as the export writes a label that holds a line break; the graph is read for such labels once, when a list does not read as one line a link, through db, the note's transaction. The text is read whole, so a trace whose own text ends in a line of hashtags, and a trace with no text, are the duplicates of their own notes too, and a vault exported from a brain and imported into it adds nothing. A note that holds anything else after the text, such as a paragraph added in Obsidian before or after its links, is not the trace's own note. Line breaks are read as \n in the note, the text and the labels alike, so a note an editor saved again with CRLF line endings is its trace's own note.

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 the graph is read through: the note's transaction, or the brain.

Returns​

Promise<boolean>

A promise of true when the note holds the trace's text.

Overrides​

MarkdownImporter.holdsTraceText


import()​

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

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

Recursively walk sourceDir and import every .md file as MarkdownImporter does, reading each note's #tags and [[wikilinks]] as well. Each import reads the brain's graph afresh: the labels it holds that have a line break are read once, when a note first needs them (see holdsTraceText). An import that inserted a note, or added a tag to a trace the brain holds, rebuilds the brain's full-text index once, after its last note, so the full-text search finds the note and the tag.

Parameters​

sourceDir​

string

Directory to recursively scan for .md files.

options?​

Pick<ImportOptions, "dedup">

dedup (default true) skips a note the brain holds.

Returns​

Promise<ImportResult>

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

Overrides​

MarkdownImporter.import


postProcess()​

protected postProcess(_filePath, _frontmatter, body, result, traceId): Promise<void>

Defined in: packages/agentos/src/cognition/memory/io/ObsidianImporter.ts:311

Post-process a successfully imported Markdown file:

  1. Warn about any embedded images (![[...]]).
  2. Extract inline #hashtags and merge them into the trace's tag list.
  3. Parse [[wikilinks]] and create knowledge_edges entries.

Parameters​

_filePath​

string

Absolute path of the source file (unused here).

_frontmatter​

TraceFrontmatter

Parsed front-matter data.

body​

string

Markdown body (content after front-matter).

result​

ImportResult

Mutable ImportResult accumulator.

traceId​

string

The ID of the just-inserted trace.

Returns​

Promise<void>

Overrides​

MarkdownImporter.postProcess