Skip to main content

Module config_watcher_fs

Module config_watcher_fs 

Source
Expand description

Filesystem watcher for settings.json — detects saves and pushes updated config to all connected WebSocket clients in real time.

Migrated onto the shared fs_watch::FsWatchPool (SPEC_SHARED_FS_WATCHER_FRAMEWORK_2026_08_07.md) — this module keeps only its own domain-specific debounce/reload/broadcast logic; the actual notify construction, refcounting, and recovery-on-failure now live in the pool, shared with every other watcher that migrates onto it.

Functions§

broadcast_full_config
Push the current FullConfigType snapshot to every connected client, in the same wire shape the initial getfullconfig RPC response uses.
is_settings_file_event 🔒
Whether a raw fs_watch event refers to a settings.json save specifically — the pool’s broadcast stream carries events for every currently-watched path in the process, not just this module’s. Matches the pre-migration code’s filter exactly: filename must be settings.json (was event.paths.iter().any(|p| p.ends_with("settings.json"))) AND the event must be a Create/Modify (was EventKind::Modify(_) | EventKind::Create(_)). A Removed event (external delete, or an editor’s unlink+recreate save) is deliberately excluded — read_config_file treats a missing file as success (defaults, no errors), so reacting to Remove would reset the live config and broadcast it to every client.
load_settings_from_disk
Load settings.json from disk into the ConfigState. Called once at startup so the backend has the user’s saved settings.
merge_settings_into_current
Merge new keys into the current in-memory SettingsType and return the result. Used by the setconfig handler to update in-memory state before the fs watcher fires.
merge_settings_to_disk
Merge a flat map of settings keys into settings.json on disk. Existing keys not present in new_keys are preserved. The fs watcher will detect the write (~300ms) and broadcast the updated config.
reload_and_broadcast 🔒
resolve_settings_dir
Resolve the directory containing settings.json.
set_connection_values
Change one connection’s settings (settings.json → connections.<name>, SPEC_REMOTES_PANE_2026_10_05.md §4.3): a null value removes a key. Edits the raw connections object read from disk, so keys AgentMux doesn’t know survive, then writes, updates the live config and broadcasts it, as setconfig does. An edit that leaves the entry unreadable is refused before anything is written. Serialized, so two quick edits can’t drop each other’s.
spawn_settings_watcher
Subscribe to settings.json via the shared FsWatchPool and broadcast config updates to all WebSocket clients on change.