feat(agent): add InvalidateBootstrapCache for IdentitySync file changes

ContextBuilder.InvalidateBootstrapCache allows IdentitySync to force
reload of bootstrap files when identity docs change on disk.
This commit is contained in:
ZanzyTHEbar 2026-02-22 22:51:49 +00:00
parent c703916a81
commit af40578d5b
2 changed files with 15 additions and 0 deletions

View file

@ -404,6 +404,14 @@ func (cb *ContextBuilder) cachedBootstrapFiles() string {
return cb.bootstrapCache
}
// InvalidateBootstrapCache forces the next BuildSystemPrompt to reload
// bootstrap files from the delegate. Called by IdentitySync when files change.
func (cb *ContextBuilder) InvalidateBootstrapCache() {
cb.cacheMu.Lock()
cb.bootstrapCache = ""
cb.cacheMu.Unlock()
}
func (cb *ContextBuilder) LoadBootstrapFiles() string {
if cb.delegate == nil {
return ""

View file

@ -49,6 +49,10 @@ type IdentitySync struct {
agentID string
store DocumentStore
// OnChange is called after CheckAndSync detects and persists file changes.
// Use it to invalidate downstream caches (e.g., bootstrap prompt cache).
OnChange func()
watcher *fsnotify.Watcher
cancel context.CancelFunc
wg sync.WaitGroup
@ -128,6 +132,9 @@ func (s *IdentitySync) CheckAndSync(ctx context.Context) error {
now := time.Now()
s.lastSync.Store(now.UnixNano())
_ = s.store.UpsertKV(ctx, s.agentID, kvLastSyncKey, now.Format(time.RFC3339Nano))
if s.OnChange != nil {
s.OnChange()
}
}
return nil
}