Repository navigation
perf: reduce file I/O in SubagentLocator (cherry-pick of upstream #110) - #1
Merged
Merged
Conversation
- hasSubagents(): Remove redundant readFile after stat size check; stat.size > 0 is sufficient to confirm non-empty files - hasSubagentsSync(): Same optimization using statSync instead of reading entire file contents - subagentBelongsToSession(): Use createReadStream + readline to stream only the first line instead of reading entire file via readFile, then close the stream immediately Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…tching Covers hasSubagents (content, empty files, name filtering, missing dir), subagentBelongsToSession (match, mismatch, leading blank lines, CRLF, empty file, invalid JSON, missing file, first line larger than stream chunk) and getProjectRootSubagentFiles filtering.
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.
Summary
Cherry-picks the
SubagentLocatorcommit (f7e7c42) from upstream matt1398#110 and adds unit tests for the class, which had no test coverage before.hasSubagents(): treatsstat.size > 0as non-empty and no longer reads the whole subagent file. This runs once per session during the project scan.subagentBelongsToSession(): reads only up to the first non-empty line throughcreateReadStream+readlineand no longer loads the whole file. Same pattern asSessionContentFilter.hasNonNoiseMessages.The upstream PR's second commit (618243f, deletes
build/entitlements.mac.plist) is not included. It is unrelated to this change. That file is unused (package.jsonpoints toresources/entitlements.mac.plist).Behavior changes
hasSubagents()now returnstruefor a subagent file that contains only whitespace. Before, it returnedfalse.subagentBelongsToSession()now skips blank lines at the start of the file. Before, a first line of only spaces made it returnfalse.Known caveat (not addressed)
SshFileSystemProvider.createReadStreampasses SFTP stream errors on to itsPassThrough, but does not passdestroy()back to the SFTP stream. An earlyfileStream.destroy()therefore probably leaves the SFTP read handle open.SessionContentFilteralready has the same problem. Here it affects only SSH projects that use the old layout, whereagent-*.jsonlfiles sit in the project root.Test plan
pnpm typecheck: cleanpnpm test: 735/735 pass (13 new intest/main/services/discovery/SubagentLocator.test.ts)security/detect-non-literal-fs-filenamewarnings, the same baseline as the existing discovery tests); Prettier clean