fix: import knowledge from .lore.md on file change and new session start#247
Merged
Conversation
Previously, knowledge file imports only ran once per gateway process lifetime in initIfNeeded(). If .lore.md changed mid-session (git pull, manual edit), changes were never picked up until a full restart. Additionally, importLoreFile() did not update the file cache after a successful import, causing shouldImportLoreFile() to re-evaluate via the slow path on every restart. Changes: - importLoreFile() now updates the mtime/hash cache after importing - Extract import logic into reusable tryImportKnowledge() function - Add fs.watch() for .lore.md and agents file with 500ms debounce - Re-check knowledge files on every new session start (isNew=true) - Clean up watchers in resetPipelineState()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
importLoreFile()now updates the mtime/hash cache after a successful import, soshouldImportLoreFile()correctly fast-paths on subsequent checks instead of re-evaluating via the slow path every restart.fs.watch()on.lore.mdand agents file (AGENTS.md) with 500ms debounce, so external changes (git pull, manual edits) are picked up live without requiring a gateway restart.tryImportKnowledge()runs on every new session start as a belt-and-suspenders fallback for cases where the watcher wasn't set up or missed an event.Problem
Knowledge file imports only ran once per gateway process lifetime in
initIfNeeded(). If.lore.mdchanged mid-session, changes were never picked up. Additionally, the missing cache update after import could cause unpredictable behavior across restarts.Changes
packages/core/src/agents-file.tsimportLoreFile()updates file cache (mtime + content hash) after successful importpackages/gateway/src/pipeline.tstryImportKnowledge(), addstartKnowledgeFileWatcher(), call on new session, clean up inresetPipelineState()packages/core/test/agents-file.test.tsshouldImportLoreFile()returns false without needing an export cycle