Skip to main content

KnowledgeBase

Struct KnowledgeBase 

Source
pub struct KnowledgeBase { /* private fields */ }
Expand description

Markdown knowledge base application layer.

Wraps VirtualFs for sandboxed file I/O, BacklinkIndex for link tracking, and provides all app-layer features (chat, journal, habits, checklist, etc.).

No kernel dependencies. Can be used standalone by any channel.

Implementations§

Source§

impl KnowledgeBase

Source

pub fn new(root: PathBuf) -> Result<Self>

Create a new KnowledgeBase for the given root directory.

Source

pub fn for_space(space_dir: &Path) -> Result<Self>

Create a new KnowledgeBase scoped to a Space’s subdirectory.

Source

pub fn root(&self) -> PathBuf

Get the root path of the knowledge base.

Source

pub fn on_file_change<F>(&self, f: F)
where F: Fn(&str, FileChange) + Send + Sync + 'static,

Register a callback to be invoked on every file change.

The callback receives (path, FileChange). Multiple callbacks can be registered.

Source

pub fn note_read(&self, path: &str) -> Result<Option<String>>

Read a note’s content.

Source

pub fn note_write(&self, path: &str, content: &str) -> Result<()>

Write a note — creates or overwrites.

Writes the .md file via VirtualFs, updates the backlink index, and notifies registered on_file_change callbacks.

Source

pub fn note_delete(&self, path: &str) -> Result<()>

Delete a note.

Source

pub fn note_restore(&self, path: &str, content: &str) -> Result<()>

Restore a note’s content without triggering file-change callbacks.

Used when reverting to a previous git version — writes the file and updates the backlink index, but does not fire on_file_change callbacks. This prevents an infinite loop where restore → write → callback → git commit → … repeats.

Source

pub fn note_move(&self, old_path: &str, new_path: &str) -> Result<()>

Move/rename a note.

Source

pub fn note_tree(&self, dir: &str) -> Result<Vec<FileEntry>>

List notes in a directory.

Source

pub fn search(&self, query: &str, limit: usize) -> Result<Vec<NoteHit>>

Search notes by file name fuzzy matching.

Note: Semantic search is handled by KnowledgeLens, not by this method.

Get backlinks for a note.

Get the full link graph for visualization.

Source

pub fn index_all(&self) -> Result<usize>

Index all markdown files in the knowledge base.

Walks the entire directory tree and builds the backlink index. Returns the number of files indexed.

Source

pub fn chat_append(&self, message: &str) -> Result<()>

Append a timestamped message to Chat.md.

Source

pub fn chat_messages(&self) -> Result<Vec<String>>

Parse Chat.md into structured message blocks.

Source

pub fn chat_delete(&self, msg_hash: &str) -> Result<bool>

Delete a specific chat message by its content hash.

Source

pub fn chat_rename(&self, msg_hash: &str, new_body: &str) -> Result<bool>

Rename a specific chat message by its content hash.

Source

pub fn chat_move_to(&self, msg_hash: &str, target_path: &str) -> Result<bool>

Move a chat message to a target file as a checklist item.

Source

pub fn journal_add_record(&self, record: &str) -> Result<()>

Add a timestamped record to today’s journal entry.

Source

pub fn journal_add_emoji(&self, emoji: &str) -> Result<()>

Add an emoji to today’s journal header.

Source

pub fn journal_today_path(&self) -> String

Get today’s journal file path (e.g., “journal/2026.05 May.md”).

Source

pub fn habits(&self, year: i32) -> Result<Habits>

Read habit tracking data for a given year.

Source

pub fn habits_last_week(&self) -> Result<Habits>

Get last week’s habit data.

Source

pub fn habits_write(&self, year: i32, habits: &Habits) -> Result<()>

Write habit data for a year.

Source

pub fn config(&self) -> Result<KnowledgeConfig>

Read the knowledge base config (config.json).

Source

pub fn set_config(&self, config: &KnowledgeConfig) -> Result<()>

Write the knowledge base config.

Source

pub fn checklist_items( &self, path: &str, ) -> Result<(Vec<String>, HashMap<String, bool>)>

Parse checklist items from a file.

Source

pub fn checklist_incomplete(&self, path: &str) -> Result<Vec<String>>

Get incomplete checklist items from a file.

Source

pub fn checklist_add(&self, path: &str, item: &str, checked: bool) -> Result<()>

Add a checklist item to a file.

Source

pub fn checklist_complete(&self, path: &str, item_hash: &str) -> Result<bool>

Complete a checklist item by hash.

Source

pub fn checklist_remove(&self, path: &str, item_or_hash: &str) -> Result<bool>

Remove a checklist item by text or hash.

Source

pub fn checklist_remove_completed(&self, path: &str) -> Result<(String, String)>

Remove all completed checklist items.

Source

pub fn run_nightly_cleanup(&self) -> Result<NightlyReport>

Run nightly cleanup.

Source

pub fn run_scheduled_tasks(&self) -> Result<Vec<String>>

Move due scheduled tasks to Chat.

Source

pub fn today_report(&self) -> Result<TodayReport>

Get today’s completion report.

Source

pub fn done_today(&self) -> Result<Vec<FileEntry>>

Get list of files completed today.

Source

pub fn markdown_to_html(&self, md: &str) -> String

Convert markdown to HTML.

Source

pub fn auto_emoji(&self, text: &str) -> String

Find an emoji for a keyword.

Source

pub fn world_clock(&self, timezone_names: &[&str]) -> Vec<TimezoneEntry>

Generate world clock report for given timezone names.

Source

pub fn mark_agent_write(&self, path: &str)

Mark a file as having been written by an agent.

Source

pub fn is_agent_write(&self, path: &str) -> bool

Check if a file was written by an agent.

Source

pub fn clear_agent_write(&self, path: &str)

Clear the agent-write marker for a file.

Extract text, images, and links from markdown content.

Source

pub fn extract_headings(&self, content: &str) -> Vec<String>

Extract headings from content for tag generation.

Trait Implementations§

Source§

impl Debug for KnowledgeBase

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,