Skip to content

Commit 5a838ec

Browse files
committed
fix(file/watcher): support flat event format for file watcher updates
Fix anomalyco#17: UI not updating immediately when creating new files/folders. The invalidateFromWatcher function now supports both event formats: - Legacy: {type: 'file.watcher.updated', properties: {file, event}} - New/Flat: {file, event} This ensures file tree updates correctly regardless of how the SDK sends events.
1 parent 82f85f1 commit 5a838ec

1 file changed

Lines changed: 27 additions & 9 deletions

File tree

‎packages/app/src/context/file/watcher.ts‎

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
import type { FileNode } from "@opencode-ai/sdk/v2"
22

3-
type WatcherEvent = {
4-
type: string
5-
properties: unknown
6-
}
3+
type WatcherEvent =
4+
| {
5+
type: "file.watcher.updated"
6+
properties: {
7+
file: string
8+
event: "add" | "change" | "unlink"
9+
}
10+
}
11+
| {
12+
file: string
13+
event: "add" | "change" | "unlink"
14+
}
715

816
type WatcherOps = {
917
normalize: (input: string) => string
@@ -16,11 +24,21 @@ type WatcherOps = {
1624
}
1725

1826
export function invalidateFromWatcher(event: WatcherEvent, ops: WatcherOps) {
19-
if (event.type !== "file.watcher.updated") return
20-
const props =
21-
typeof event.properties === "object" && event.properties ? (event.properties as Record<string, unknown>) : undefined
22-
const rawPath = typeof props?.file === "string" ? props.file : undefined
23-
const kind = typeof props?.event === "string" ? props.event : undefined
27+
// Support both old format { type, properties } and new format { file, event }
28+
let rawPath: string | undefined
29+
let kind: string | undefined
30+
31+
if ("type" in event && event.type === "file.watcher.updated" && "properties" in event) {
32+
// Old format
33+
const props = event.properties
34+
rawPath = typeof props?.file === "string" ? props.file : undefined
35+
kind = typeof props?.event === "string" ? props.event : undefined
36+
} else if ("file" in event && "event" in event) {
37+
// New format (flat structure)
38+
rawPath = typeof event.file === "string" ? event.file : undefined
39+
kind = typeof event.event === "string" ? event.event : undefined
40+
}
41+
2442
if (!rawPath) return
2543
if (!kind) return
2644

0 commit comments

Comments
 (0)