Repository navigation
Conversation
|
Thanks for updating your PR! It now meets our contributing guidelines. 👍 |
There was a problem hiding this comment.
This works as described. In a non-git project, @AGENTS now lists the root AGENTS.md symlink next to app-a/AGENTS.md; on the base branch only the latter appears. The new test fails on the base branch and passes here, and typecheck:tsc is clean. I also checked that the depth-1 rg --follow listing run in a subdirectory still honours ignore rules from parent folders, so links excluded by a parent .ignore stay out of the index.
The public API is unchanged: Ripgrep.FindInput.maxDepth is a new optional field on an internal interface.
One inline note on refresh cost in large home folders. It doesn't block this change.
| // Look for links only in the directories this scan walked, and let a depth-1 `--follow` listing of | ||
| // those directories decide which links are visible files. It applies the scan's ignore and hidden | ||
| // rules, and a symlinked directory or a broken link yields nothing, so no link is ever traversed. | ||
| if (next.files.size < limit) |
There was a problem hiding this comment.
This runs a files.list for every directory found by the main scan, on every refresh (at most once per 10s while searching). In the home-folder case, where up to 100k files are indexed, that can mean thousands of directory listings each time just to find symlinks, even though most folders have none (see #55937 for how expensive home folders already are). Since later refreshes run in the background it's not a correctness problem. Still, it may be worth limiting this to the first scan, or only re-listing directories whose mtime changed, so the steady-state cost doesn't grow with the size of the tree.
There was a problem hiding this comment.
Good point, thanks. I changed it so only the first scan lists every walked directory. The layer now remembers which directories held visible symlinked files, and a refresh lists only the root, directories that are new since the last scan, and the ones that held links. I skipped the mtime idea because on workspace environments each stat is a process too, so it would cost about the same as the listing it replaces. On a non-git folder with 4.3k directories, a refresh now does 9 listings instead of 4,739, and the symlink step drops from about 170-360 ms to about 55 ms. The trade-off is that a link added later to an existing folder without links (other than the root) shows up only in the next session; there is a test for the refresh behaviour.
The ripgrep-backed index (non-git, home and workspace Locations) runs rg --files without --follow, which omits every symlink, so a workspace AGENTS.md linked from a rules repo never showed up in the @ picker. After the scan, list the directories it walked through the Location environment and, for each one that holds symlinks, run a depth-1 rg --files --follow there. Only links that resolve to regular files are added, under their link path, with the same ignore and hidden rules. Symlinked directories are never traversed and broken links are skipped.
…symlink index A refresh of the ripgrep-backed index listed every directory the scan walked to find symlinks, so its cost grew with the tree (thousands of listings per refresh in a home folder). Remember which listed directories held visible symlinked files. A refresh lists the root, directories that are new since the last scan and directories that held links; a directory found without links is not listed again. This keeps per-directory I/O off the steady state, which matters most on workspace environments where every stat or list is a process.
1ff80b7 to
1133ce6
Compare
There was a problem hiding this comment.
This still works on the new head: running the #59539 repro in a non-git project, @AGENTS now offers the root AGENTS.md symlink, while the base branch doesn't (screenshots below). search.test.ts passed 11/11 in three runs and typecheck:tsc is clean.
The earlier point about refresh cost is addressed: a refresh now re-lists only the root, new folders and folders that had visible links last time.
The public API is unchanged: Ripgrep.FindInput.maxDepth is a new optional field on an internal interface.
One small inline note about folders whose symlinks are all broken or ignored. It doesn't block the change.
| }), | ||
| }) | ||
| files.forEach(add) | ||
| found.set(directory, files) |
There was a problem hiding this comment.
When a folder's symlinks were all broken or ignored, files is empty, so the folder is saved exactly like one with no symlinks and is skipped on every later refresh. If such a link starts working later (for example, its target is cloned or created after OpenCode starts), it won't show up until restart, even though this folder does contain symlinks. Saving "had symlinks" separately from "had visible links" (e.g. skip only when links.size === 0) would keep the saving for folders without any symlinks and close this gap.
There was a problem hiding this comment.
Fixed in 6c6a29d: a folder now stays on the refresh list when it holds any symlink, broken or ignored ones included, so a link that starts resolving later shows up on the next refresh. Folders without symlinks are still skipped. The test now has a broken link whose target is created after the first scan.
There was a problem hiding this comment.
The broken or ignored symlink point is addressed. A folder is now skipped on refresh only when it had no symlinks at all, and the new test case covers a broken link that starts resolving later. The #59539 repro still passes on this head: @AGENTS offers the root AGENTS.md symlink here but not on the base branch (screenshots below). search.test.ts passed 11/11 in three runs and typecheck:tsc is clean.
The public API is unchanged: Ripgrep.FindInput.maxDepth is a new optional field on an internal interface.
No further concerns.




Issue for this PR
Closes #59539
Type of change
What does this PR do?
As a solo developer I work across many git repositories, and I keep one "super" AGENTS.md (with its rule files) in a repository of its own, symlinked into the folder that holds all the other repos. OpenCode loads that symlinked file as instructions, but the
@picker never lists it: in a non-git folder the index isrg --fileswithout--follow, and ripgrep drops every symlink in that mode. Details and repro in the issue.The fix is deliberately narrower than #18291 / #29102: it indexes symlinks to files only and never enters symlinked directories.
How
FileSystemSearchripgrep layer: the existingrg --filesscan is unchanged. Afterwards, the directories that scan walked are listed through the Location environment (Environment.files.list, which tags entries with their ownsymlinktype). For each directory that contains symlinks, onerg --files --follow --max-depth 1runs in that directory. A link is added to the index, under its link path, only when that listing prints it..gitignore/.ignore, and excluded or unwalked directories (such as the home Protected excludes) are handled the same way. Directories under an exclude are never walked, so they are never listed.node:fsdirectly.Ripgrep.findgains an optionalmaxDepth(--max-depth).@search went from about 300 ms to about 440 ms locally. A refresh no longer grows with the tree: on the same workspace it does 9 listings and 9 rg processes instead of 4,739 listings, and the symlink step takes about 55 ms instead of about 170-360 ms. It avoids a stat per directory on purpose: on workspace environments every stat or list is a process, so an mtime check would cost about as much as the listing it saves.The fff layer (git repos) has the same gap: a symlink to a file is not indexed by
@ff-labs/fff-bun, whether it is tracked (mode 120000) or untracked. That scanner is native code in an external package, so this PR does not change it.How did you verify your code works?
packages/core/test/filesystem/search.test.ts. A temp folder (not a git repo) holds a root file linkAGENTS.md -> .agents/AGENTS.md, a nested file link, a link that.ignoreexcludes, a symlinked directory, a broken link and aloop -> .cycle. OnlyAGENTS.mdandapp/AGENTS.mdare added, nothing appears underlinked/orloop/, and the scan finishes. The test fails ondev(it gets[]forAGENTS) and passes with this change. It is skipped on Windows, because creating symlinks there needs elevated privileges.files.listcalls through a wrapped environment: after the first scan, a refresh lists only the root, a new directory and the directory that already held a link, and finds the links added to all three; the unchanged link-free directories are not listed again (this test fails on the first commit, which re-listedappandapp/sub).bun test test/filesystem/search.test.ts: 11 pass.bun test test/filesystem: 66 pass, 0 fail.bun run check(lint + typecheck) at the repo root passes.AGENTS.mdsymlink now lists it in the@picker results.Visual
Not included: the change is a missing entry in the
@picker results.Screenshots / recordings
Not a UI change.
Checklist
Added by the opencode bot (AI-generated).
Related: #53958, #55937