Skip to content

feat(daemon): lazy background indexing on first search#36

Draft
andrewgazelka wants to merge 1 commit intomixedbread-ai:mainfrom
andrewgazelka:andrewgazelka/daemon-watch
Draft

feat(daemon): lazy background indexing on first search#36
andrewgazelka wants to merge 1 commit intomixedbread-ai:mainfrom
andrewgazelka:andrewgazelka/daemon-watch

Conversation

@andrewgazelka
Copy link

@andrewgazelka andrewgazelka commented Nov 25, 2025

Closes: #34

Requires #35 to be fixed to test.

  • test

Warning

This is an AI-assisted PR where I have given it the architecture. I want to refine before promoting to ready for review.

Eliminate the need to manually run mgrep watch by automatically spawning a background daemon on first mgrep search invocation.

Key features:

  • Lazy start: daemon spawns automatically when you first search
  • One daemon per directory with hierarchy awareness:
    • Parent directory daemon covers all subdirectories
    • Starting a parent daemon consolidates/kills child daemons
  • Atomic startup using O_EXCL file locking to prevent race conditions
  • New commands: daemon:list and daemon:stop for management

Implementation:

  • Add src/lib/daemon.ts with daemon lifecycle management
  • Modify search.ts to call ensureDaemon() before searching
  • Add SIGTERM handler to watch.ts for graceful shutdown
  • Add daemon:list and daemon:stop commands to CLI

State files stored in ~/.local/state/mgrep/daemons/

Update README to reflect that mgrep watch is now optional and document the new daemon management commands.

Future consideration

Perhaps add idle timeout so daemons auto-stop after inactivity (e.g., 30 minutes). Currently daemons run indefinitely until manually stopped with mgrep daemon:stop.

Eliminate the need to manually run `mgrep watch` by automatically
spawning a background daemon on first `mgrep search` invocation.

Key features:
- Lazy start: daemon spawns automatically when you first search
- One daemon per directory with hierarchy awareness:
  - Parent directory daemon covers all subdirectories
  - Starting a parent daemon consolidates/kills child daemons
- Atomic startup using O_EXCL file locking to prevent race conditions
- New commands: `daemon:list` and `daemon:stop` for management

Implementation:
- Add src/lib/daemon.ts with daemon lifecycle management
- Modify search.ts to call ensureDaemon() before searching
- Add SIGTERM handler to watch.ts for graceful shutdown
- Add daemon:list and daemon:stop commands to CLI

State files stored in ~/.local/state/mgrep/daemons/

Update README to reflect that mgrep watch is now optional and
document the new daemon management commands.

Future consideration: Add idle timeout so daemons auto-stop after
inactivity (e.g., 30 minutes). Currently daemons run indefinitely
until manually stopped with `mgrep daemon:stop`.

Closes: mixedbread-ai#34
andrewgazelka referenced this pull request Nov 25, 2025
* feat: add a stub mcp server to start watch

To start the watch command in the background we can use a mcp server
and start the watch in the background. This way we can start watch
for all agents that use mcp.

* feat: add a install codex command

* chore: only register the signal handlers when mcp is called

* chore: await for exec

* chore: properly handle AGENTS.md file

* chore: do not add the skill twice

* chore: respect the store selection in the parameters

* chore: resolve wrong parameter count

* chore: fix formating
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.

run mgrep watch lazily

1 participant