Skip to content

Refactor: shared broadcast/listen, watchDir, task lookup - #229

Merged
nthomsencph merged 4 commits into
mainfrom
refactor/shared-plumbing
Nov 9, 2026
Merged

nthomsencph merged 4 commits into
mainfrom
refactor/shared-plumbing

Conversation

@nthomsencph

Copy link
Copy Markdown
Collaborator

Three behaviour-preserving consolidations from the cross-PR design review. This merges before #227 and #228, which get rebased onto it and switched to the new helpers.

1. Broadcast and listen

  • broadcast(channel, ...args) in src/main/utils/broadcast.ts sends to every live window. It skips destroyed windows and logs a failed send instead of throwing.
  • It replaces the private copies in servicesIpc.ts and ScaffoldService.ts and 12 hand-rolled getAllWindows() loops in 11 files.
  • Targeted sends to one window are left alone: wizard, HookServer focus, accessPrompt, drawerTabs, the setSender services, and TokenStatsService's sender path.
  • In preload, listen<T>(channel) builds the onX(callback) => unsubscribe pairs. 28 of them now use it. The exposed API is unchanged.
  • onOrchestratorAccessRequest stays hand-written: it listens on two channels and reshapes the payload.

2. watchDir

  • watchDir(dir, { filter, debounceMs, onChange }) => close in src/main/utils/watchDir.ts. It watches the folder non-recursively, debounces matching events, swallows watch errors and returns close().
  • FileWatcherService and PortsConfigWatcher now use it. Filters and timings (500 ms, 2 s) are unchanged.
  • watchDir throws when the folder can't be watched, so each caller keeps its own handling of that.

3. Task lookup

  • selectTaskById(state, id) and selectTaskByPath(state, path) in projectsStore.ts. Both return the stored task by reference, so they're safe as hook selectors without useShallow.
  • 10 lookups in 8 files now use them, and so does selectActiveTask.

One normalisation: the broadcasts that didn't catch send errors before now catch them and log. Nothing else changes.

Tests: broadcast (4), preload listen with a stub ipcRenderer (3), watchDir with a fake fs.watch and fake timers (5), task lookup (1). Bumps to 0.23.0.

🤖 Generated with Claude Code

broadcast(channel, ...args) in src/main/utils/broadcast.ts sends to every
live window, skips destroyed ones and logs instead of throwing. It replaces
the private copies in servicesIpc and ScaffoldService and the hand-rolled
getAllWindows loops in 11 other places. Targeted sends to one window stay.

preload's listen<T>(channel) builds the onX(callback) => unsubscribe pairs;
28 of them now use it. The exposed API is unchanged.

Claude goes brr.. via Dash
watchDir(dir, { filter, debounceMs, onChange }) in src/main/utils/watchDir.ts
watches a folder non-recursively, debounces matching events, swallows watch
errors and returns close(). FileWatcherService and PortsConfigWatcher now use
it; their filters, debounce timings and arm-time error handling are unchanged
(watchDir throws if the folder can't be watched, and each caller keeps its
own handling of that).

Claude goes brr.. via Dash
Two selectors next to selectActiveTask in projectsStore find a task across
every project (archived included) and return the stored object, so a hook
can use them without useShallow. Ten hand-rolled lookups over
Object.values(tasksByProject), in eight files, now use them, and so does
selectActiveTask.

Claude goes brr.. via Dash
Claude goes brr.. via Dash
@nthomsencph
nthomsencph merged commit 12f8d59 into main Nov 9, 2026
5 checks passed
@nthomsencph nthomsencph mentioned this pull request Nov 9, 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