Repository navigation
Conversation
…or exact lookups Replace the Codex integration, which appended a "MANDATORY / NEVER use grep" skill to ~/.codex/AGENTS.md and registered an MCP server without tools. Codex then stopped searching any other way. The integration is now a native Codex plugin from the same repository marketplace as the Claude plugin: - MCP server (`mgrep mcp --expose-tools`) with one read-only `search` tool. It runs outside Codex's network sandbox, so searches need no approval prompt, and it syncs the session directory in the background for the lifetime of the session. - SessionStart hook that only adds neutral guidance: mgrep for conceptual questions, rg/grep for exact strings and symbols. - Short neutral skill. - `install-codex` adds the marketplace and installs the plugin; `uninstall-codex` reverses it. Both clean up the legacy AGENTS.md block and MCP registration. Supporting changes the MCP tool needs: search logic extracted to src/lib/search.ts and shared by the CLI and the tool, non-interactive store creation for the MCP server, version read from package.json, and startWatch no longer calls process.exit and reports whether watching started.
Every agent session starts its own `mgrep watch` (Claude hook) or MCP server watcher (Codex). Sessions in /repo and /repo/services ran two watchers that both hashed and uploaded everything under /repo/services. Watchers on the same store now coordinate through a claim registry in ~/.mgrep/watchers (O_EXCL claim files, building on the lock design of the unmerged prevent-multiple-watches-on-same-dir branch): - The first started watcher wins. A watcher whose directory is covered by an earlier active watcher stands by: no initial sync, no fs.watch, no uploads. It takes over when that watcher exits. - An active watcher excludes subtrees owned by earlier active watchers inside its tree, and gives them back when they exit. - A directory with its own .mgreprc.yaml/.yml is a project boundary: it is never covered by an ancestor, and ancestors neither upload nor delete files inside it. - Claims of dead processes, and unparsable claims older than 30 s, are pruned. Claims are released on exit and SIGTERM; the Claude SessionEnd hook now sends SIGTERM instead of SIGKILL. In the MCP server a covered watcher resolves immediately, so searches do not wait for a sync that another session already owns. A signalled CLI watcher exits immediately, also during a sync. After a quota error, poll-time re-syncs back off for 10 minutes (MGREP_WATCH_QUOTA_BACKOFF_MS) and the quota message prints once.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Every agent session starts its own watcher: the Claude SessionStart hook runs
mgrep watch, and with #153 the Codex MCP server watches the session directory. Two sessions in/repoand/repo/servicestherefore run two watchers that both hash and upload everything under/repo/services. With several sessions in one repository, the same files are hashed and uploaded several times. The unmergedprevent-multiple-watches-on-same-dirbranch locks only an identical directory, so a parent and a child directory still double up.Expected: one active watcher per directory tree and store, without any session losing sync when another ends.
Change
Watchers on the same store coordinate through a claim registry in
~/.mgrep/watchers, one O_EXCL claim file per store and real path. This extends the lock design fromprevent-multiple-watches-on-same-dirinstead of adding a second mechanism.fs.watch, no uploads. It polls the registry and takes over, with a sync, when the covering watcher exits./repoafter one in/repo/servicesskips that subtree and takes it back when the child exits..mgreprc.yaml/.ymlalways gets its own watcher. Ancestors neither upload nor delete files inside it, sinceinitialSyncgetsexcludedRoots.MGREP_WATCH_QUOTA_BACKOFF_MS), and the quota message prints once.Not handled: creating or removing a
.mgreprcfile while a watcher runs takes effect when a watcher next becomes active, the same as config changes today.Scope and approval
There is no prior issue or discussion. It builds on the maintainers' unmerged
prevent-multiple-watches-on-same-dirbranch. Happy to split it or align with that branch differently if you prefer.Verification
test/watch-coordination.bats:.mgreprc.yamland.ymlboundaries;test/mcp.bats: an MCP server in a directory already covered by an activemgrep watchanswers a search in under 5 s, withMGREP_MCP_SYNC_WAIT_MS=30000, no "still running" note and no own sync. After SIGTERM to the active watcher, the MCP server's watcher takes over the claim.mgrep watchin the root is active, and one inservices/logs "Covered by mgrep watch (pid …) for ; standing by", with one claim file.services/watcher takes over, and no claims or processes are left after it stops.Not checked: Linux and Windows (developed on macOS), and many concurrent sessions beyond the tested two or three.
Model and harness: Claude Opus 5.5 (1M context) in Claude Code for design, review and verification; GPT-6.1-Sol in Codex for implementation.