Skip to content

fix: import knowledge from .lore.md on file change and new session start#247

Merged
BYK merged 1 commit into
mainfrom
fix/knowledge-file-import
May 12, 2026
Merged

fix: import knowledge from .lore.md on file change and new session start#247
BYK merged 1 commit into
mainfrom
fix/knowledge-file-import

Conversation

@BYK
Copy link
Copy Markdown
Owner

@BYK BYK commented May 12, 2026

Summary

  • Bug fix: importLoreFile() now updates the mtime/hash cache after a successful import, so shouldImportLoreFile() correctly fast-paths on subsequent checks instead of re-evaluating via the slow path every restart.
  • File watcher: Adds fs.watch() on .lore.md and agents file (AGENTS.md) with 500ms debounce, so external changes (git pull, manual edits) are picked up live without requiring a gateway restart.
  • New-session re-check: 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.md changed mid-session, changes were never picked up. Additionally, the missing cache update after import could cause unpredictable behavior across restarts.

Changes

File Change
packages/core/src/agents-file.ts importLoreFile() updates file cache (mtime + content hash) after successful import
packages/gateway/src/pipeline.ts Extract tryImportKnowledge(), add startKnowledgeFileWatcher(), call on new session, clean up in resetPipelineState()
packages/core/test/agents-file.test.ts Test verifying import updates cache so shouldImportLoreFile() returns false without needing an export cycle

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()
@BYK BYK merged commit 8fd43d8 into main May 12, 2026
7 checks passed
@BYK BYK deleted the fix/knowledge-file-import branch May 12, 2026 12:45
This was referenced May 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant