Now liveThe Skillselion MCP - thousands of ranked skills, loaded into your agent mid-task. No install.Get it →
builderio avatar

Sse File Watcher

  • 1 installs
  • 4.4k repo stars
  • Updated August 2, 2026
  • builderio/agent-native

sse-file-watcher is an agent-native framework skill for keeping the UI in sync with agent file writes via a server file watcher and Server-Sent Events.

About

A skill for the agent-native framework describing how to keep the UI in sync with agent file changes using Server-Sent Events. A developer uses it when setting up real-time file sync, wiring query invalidation for a new data model, or debugging a UI that will not update. A server-side chokidar watcher streams file events that trigger React Query invalidation in the browser.

  • Keeps the UI in sync with agent file writes via Server-Sent Events, no polling
  • Uses a single recursive chokidar watcher and createSSEHandler from core
  • Recommends staleTime and path-based onEvent filtering to avoid cache thrashing

Sse File Watcher by the numbers

  • 1 all-time installs (skills.sh)
  • Ranked #3,818 of 4,348 Backend & APIs skills by installs in the Skillselion catalog
  • Data as of Aug 3, 2026 (Skillselion catalog sync)
At a glance

sse-file-watcher capabilities & compatibility

Capabilities
frontend · api development
Use cases
frontend · api development
From the docs

What sse-file-watcher says it does

The UI stays in sync with agent changes through Server-Sent Events. When the agent writes a file, the UI updates automatically — no polling, no manual refresh.
SKILL.md
Don't create per-model `fs.watch()` instances — `createFileWatcher("./data")` watches recursively. One watcher is enough.
SKILL.md
Use `staleTime: 2000` on React Query to debounce refetches
SKILL.md
npx skills add https://github.com/builderio/agent-native --skill sse-file-watcher

Add your badge

Show developers this skill is listed on Skillselion. Paste this into your README.

Listed on Skillselion
Installs1
repo stars4.4k
Last updatedAugust 2, 2026
Repositorybuilderio/agent-native

What it does

Set up SSE-based real-time UI sync so agent writes to data/ invalidate the right React Query caches.

Who is it for?

Making the files-as-database pattern feel real-time by streaming agent file writes to the UI.

Skip if: Polling for changes or creating per-model fs.watch instances alongside the shared watcher.

When should I use this skill?

Setting up real-time file sync, wiring query invalidation for new data models, or debugging UI not updating.

What you get

File writes stream over SSE and invalidate the matching React Query caches so the UI updates automatically.

By the numbers

  • Describes a 3-step how-it-works flow
  • Ships a 5-row troubleshooting table

Files

SKILL.mdMarkdownGitHub ↗

SSE File Watcher

Rule

The UI stays in sync with agent changes through Server-Sent Events. When the agent writes a file, the UI updates automatically — no polling, no manual refresh.

Why

The agent modifies files on disk, but the UI runs in the browser. SSE bridges this gap: a file watcher on the server detects changes, streams them to the browser, and React Query invalidates the relevant caches. This is what makes the "files as database" pattern feel real-time.

How It Works

1. Server watches the data directory with chokidar. The watcher is set up in a shared module (server/lib/watcher.ts) and the SSE endpoint is a file-based route:

   // server/lib/watcher.ts
   import { createFileWatcher } from "@agent-native/core";
   export const watcher = createFileWatcher("./data");
   // server/routes/api/events.get.ts
   import { createSSEHandler } from "@agent-native/core";
   import { watcher } from "../../lib/watcher.js";
   export default createSSEHandler(watcher);

2. Client listens for changes and invalidates React Query caches:

   import { useFileWatcher } from "@agent-native/core";
   useFileWatcher({ queryClient, queryKeys: ["files", "projects"] });

3. When the agent writes to data/, chokidar detects it, SSE pushes the event, and React Query refetches the affected queries.

Don't

  • Don't poll for changes — SSE handles it
  • Don't create per-model fs.watch() instances — createFileWatcher("./data") watches recursively. One watcher is enough.
  • Don't create your own EventSource connections alongside useFileWatcher — use the onEvent callback for custom handling

Query Key Mapping

By default, useFileWatcher invalidates all listed query keys on every file change. For apps with multiple data models, this causes unnecessary refetches. Use path-based filtering via the onEvent callback:

useFileWatcher({
  queryClient,
  queryKeys: [], // don't auto-invalidate everything
  onEvent: (data) => {
    if (data.path?.includes("projects")) {
      queryClient.invalidateQueries({ queryKey: ["projects"] });
    } else if (data.path?.includes("settings")) {
      queryClient.invalidateQueries({ queryKey: ["settings"] });
    }
  },
});

To prevent cache thrashing during rapid agent writes, set staleTime on your queries:

useQuery({
  queryKey: ["projects"],
  queryFn: fetchProjects,
  staleTime: 2000, // don't refetch within 2 seconds
});

Performance

When the agent writes many files rapidly (e.g., during self-modification), each write fires a chokidar event → SSE broadcast → React Query invalidation. This can cause excessive refetching.

Mitigations:

  • Use staleTime: 2000 on React Query to debounce refetches
  • Use path-based filtering (see Query Key Mapping) to limit which queries invalidate

Troubleshooting

SymptomCheck
UI not updating after agent writesIs useFileWatcher called with the correct queryClient? Are the queryKeys matching your useQuery keys?
SSE not firingOpen browser devtools → Network tab → filter by EventStream. Is /api/events connected? Is the server running?
Watcher not detecting changesIs the path correct? createFileWatcher("./data") is relative to CWD. Check the server's working directory.
Constant reconnectionsCheck for server crashes in terminal output.
High CPU / event stormsThe agent is writing many files rapidly. Add staleTime to queries and use path-based filtering.

Related Skills

  • files-as-database — SSE watches the data files that store application state
  • scripts — Script outputs written to data/ trigger SSE events
  • self-modifying-code — Agent code edits trigger SSE events; rapid edits can cause event storms

Related skills

Backend & APIsbackendfrontend

This week in AI coding

Five minutes, every Monday - the tools, releases and tactics for developers.

unsubscribe anytime.