Skip to content

[Feat] Add per-task context folder file watching via fs.watch#156

Merged
samzong merged 1 commit intomainfrom
feat/context-file-watching
Mar 24, 2026
Merged

[Feat] Add per-task context folder file watching via fs.watch#156
samzong merged 1 commit intomainfrom
feat/context-file-watching

Conversation

@samzong
Copy link
Copy Markdown
Collaborator

@samzong samzong commented Mar 24, 2026

Summary

Add live file watching for per-task context folders. When users add context folders to a task, file changes (create/modify/delete) are detected via fs.watch and the file list auto-refreshes — no manual re-add needed.

Type of change

  • [Feat] new feature

Why is this needed?

Context folder file lists were static — only refreshed on manual actions like re-adding the folder. Users had no way to see newly created files without closing and re-opening the folder. This makes the context folder feature feel live: create or delete a file and the count updates within ~1 second.

What changed?

  • New file-watcher.ts module in main process: fs.watch({ recursive: true }) manager with 500ms debounce, max 10 watchers per task, silent error handling (EPERM/ENOENT), initial synthetic event suppression, and full cleanup on app quit via unwatchAll()
  • Two new IPC handlers in context-handlers.ts: context:watch-folder and context:unwatch-folder
  • Three new preload bridge methods: watchContextFolder, unwatchContextFolder, onContextFilesChanged
  • ChatInput watcher lifecycle: watch on folder add, unwatch on remove, switch watchers on task change, cleanup on unmount
  • Race-condition guard (refreshIdRef) prevents stale async IPC results from overwriting fresh ones
  • Live text file count displayed next to context folder pills in ChatInput

Architecture impact

  • Owning layer: main (file-watcher.ts, context-handlers.ts) / preload (bridge) / renderer (ChatInput.tsx)
  • Cross-layer impact: yes — new IPC channel context:files-changed flows main → renderer via sendToWindow (reuses existing window-utils.ts utility)
  • Invariants touched from docs/architecture-invariants.md: none — context folders are client-only state, not persisted to DB, no message persistence paths affected
  • Why those invariants remain protected: file watching only triggers UI refresh (file count); no writes to DB, no message creation, no gateway interaction

Linked issues

N/A

Validation

  • pnpm lint
  • pnpm test
  • pnpm build
  • Manual smoke test
  • Not run

Commands, screenshots, or notes:

pnpm check (lint + architecture + format + typecheck + test) — all passed, 88 tests green

Screenshots or recordings

N/A — file count label is a plain text span next to existing folder pills, no layout or design-system changes.

Release note

  • No user-facing change. Release note is NONE.
  • User-facing change. Release note is included below.
Context folders now auto-refresh when files are created, modified, or deleted. A live file count is shown next to each folder pill.

Checklist

  • The PR title uses at least one approved prefix: [Feat], [Fix], [UI], [Docs], [Refactor], [Build], or [Chore]
  • The summary explains both what changed and why
  • Validation reflects the commands actually run for this PR
  • Architecture impact is described and references any touched invariants
  • Cross-layer changes are explicitly justified
  • The release note block is accurate

@github-actions
Copy link
Copy Markdown
Contributor

Hi @samzong,
Thanks for your pull request!
If the PR is ready, use the /auto-cc command to assign Reviewer to Review.
We will review it shortly.

Details

Instructions for interacting with me using comments are available here.
If you have questions or suggestions related to my behavior, please file an issue against the gh-ci-bot repository.

@samzong samzong merged commit 1264996 into main Mar 24, 2026
6 checks passed
@samzong samzong deleted the feat/context-file-watching branch March 24, 2026 06:20
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