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
impl KnowledgeBase
Sourcepub fn new(root: PathBuf) -> Result<Self>
pub fn new(root: PathBuf) -> Result<Self>
Create a new KnowledgeBase for the given root directory.
Sourcepub fn for_space(space_dir: &Path) -> Result<Self>
pub fn for_space(space_dir: &Path) -> Result<Self>
Create a new KnowledgeBase scoped to a Space’s subdirectory.
Sourcepub fn on_file_change<F>(&self, f: F)
pub fn on_file_change<F>(&self, f: F)
Register a callback to be invoked on every file change.
The callback receives (path, FileChange).
Multiple callbacks can be registered.
Sourcepub fn note_write(&self, path: &str, content: &str) -> Result<()>
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.
Sourcepub fn note_delete(&self, path: &str) -> Result<()>
pub fn note_delete(&self, path: &str) -> Result<()>
Delete a note.
Sourcepub fn search(&self, query: &str, limit: usize) -> Result<Vec<NoteHit>>
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.
Sourcepub fn backlinks_for(&self, path: &str) -> Vec<Backlink>
pub fn backlinks_for(&self, path: &str) -> Vec<Backlink>
Get backlinks for a note.
Sourcepub fn link_graph(&self) -> LinkGraph
pub fn link_graph(&self) -> LinkGraph
Get the full link graph for visualization.
Sourcepub fn index_all(&self) -> Result<usize>
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.
Sourcepub fn chat_append(&self, message: &str) -> Result<()>
pub fn chat_append(&self, message: &str) -> Result<()>
Append a timestamped message to Chat.md.
Sourcepub fn chat_messages(&self) -> Result<Vec<String>>
pub fn chat_messages(&self) -> Result<Vec<String>>
Parse Chat.md into structured message blocks.
Sourcepub fn chat_delete(&self, msg_hash: &str) -> Result<bool>
pub fn chat_delete(&self, msg_hash: &str) -> Result<bool>
Delete a specific chat message by its content hash.
Sourcepub fn chat_rename(&self, msg_hash: &str, new_body: &str) -> Result<bool>
pub fn chat_rename(&self, msg_hash: &str, new_body: &str) -> Result<bool>
Rename a specific chat message by its content hash.
Sourcepub fn chat_move_to(&self, msg_hash: &str, target_path: &str) -> Result<bool>
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.
Sourcepub fn journal_add_record(&self, record: &str) -> Result<()>
pub fn journal_add_record(&self, record: &str) -> Result<()>
Add a timestamped record to today’s journal entry.
Sourcepub fn journal_add_emoji(&self, emoji: &str) -> Result<()>
pub fn journal_add_emoji(&self, emoji: &str) -> Result<()>
Add an emoji to today’s journal header.
Sourcepub fn journal_today_path(&self) -> String
pub fn journal_today_path(&self) -> String
Get today’s journal file path (e.g., “journal/2026.05 May.md”).
Sourcepub fn habits_last_week(&self) -> Result<Habits>
pub fn habits_last_week(&self) -> Result<Habits>
Get last week’s habit data.
Sourcepub fn habits_write(&self, year: i32, habits: &Habits) -> Result<()>
pub fn habits_write(&self, year: i32, habits: &Habits) -> Result<()>
Write habit data for a year.
Sourcepub fn config(&self) -> Result<KnowledgeConfig>
pub fn config(&self) -> Result<KnowledgeConfig>
Read the knowledge base config (config.json).
Sourcepub fn set_config(&self, config: &KnowledgeConfig) -> Result<()>
pub fn set_config(&self, config: &KnowledgeConfig) -> Result<()>
Write the knowledge base config.
Sourcepub fn checklist_items(
&self,
path: &str,
) -> Result<(Vec<String>, HashMap<String, bool>)>
pub fn checklist_items( &self, path: &str, ) -> Result<(Vec<String>, HashMap<String, bool>)>
Parse checklist items from a file.
Sourcepub fn checklist_incomplete(&self, path: &str) -> Result<Vec<String>>
pub fn checklist_incomplete(&self, path: &str) -> Result<Vec<String>>
Get incomplete checklist items from a file.
Sourcepub fn checklist_add(&self, path: &str, item: &str, checked: bool) -> Result<()>
pub fn checklist_add(&self, path: &str, item: &str, checked: bool) -> Result<()>
Add a checklist item to a file.
Sourcepub fn checklist_complete(&self, path: &str, item_hash: &str) -> Result<bool>
pub fn checklist_complete(&self, path: &str, item_hash: &str) -> Result<bool>
Complete a checklist item by hash.
Sourcepub fn checklist_remove(&self, path: &str, item_or_hash: &str) -> Result<bool>
pub fn checklist_remove(&self, path: &str, item_or_hash: &str) -> Result<bool>
Remove a checklist item by text or hash.
Sourcepub fn checklist_remove_completed(&self, path: &str) -> Result<(String, String)>
pub fn checklist_remove_completed(&self, path: &str) -> Result<(String, String)>
Remove all completed checklist items.
Sourcepub fn run_nightly_cleanup(&self) -> Result<NightlyReport>
pub fn run_nightly_cleanup(&self) -> Result<NightlyReport>
Run nightly cleanup.
Sourcepub fn run_scheduled_tasks(&self) -> Result<Vec<String>>
pub fn run_scheduled_tasks(&self) -> Result<Vec<String>>
Move due scheduled tasks to Chat.
Sourcepub fn today_report(&self) -> Result<TodayReport>
pub fn today_report(&self) -> Result<TodayReport>
Get today’s completion report.
Sourcepub fn done_today(&self) -> Result<Vec<FileEntry>>
pub fn done_today(&self) -> Result<Vec<FileEntry>>
Get list of files completed today.
Sourcepub fn markdown_to_html(&self, md: &str) -> String
pub fn markdown_to_html(&self, md: &str) -> String
Convert markdown to HTML.
Sourcepub fn auto_emoji(&self, text: &str) -> String
pub fn auto_emoji(&self, text: &str) -> String
Find an emoji for a keyword.
Sourcepub fn world_clock(&self, timezone_names: &[&str]) -> Vec<TimezoneEntry>
pub fn world_clock(&self, timezone_names: &[&str]) -> Vec<TimezoneEntry>
Generate world clock report for given timezone names.
Sourcepub fn mark_agent_write(&self, path: &str)
pub fn mark_agent_write(&self, path: &str)
Mark a file as having been written by an agent.
Sourcepub fn is_agent_write(&self, path: &str) -> bool
pub fn is_agent_write(&self, path: &str) -> bool
Check if a file was written by an agent.
Sourcepub fn clear_agent_write(&self, path: &str)
pub fn clear_agent_write(&self, path: &str)
Clear the agent-write marker for a file.
Sourcepub fn extract_text_imgs_links(&self, text: &str) -> ExtractResult
pub fn extract_text_imgs_links(&self, text: &str) -> ExtractResult
Extract text, images, and links from markdown content.
Sourcepub fn extract_headings(&self, content: &str) -> Vec<String>
pub fn extract_headings(&self, content: &str) -> Vec<String>
Extract headings from content for tag generation.