Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@kira-ariaki
Copy link
Contributor

Summary

walkDir now follows symbolic links using fs.stat() to determine if the target is a file or directory. This enables:

  • Symlinked markdown files inside memory/ to be indexed
  • Symlinked directories inside memory/ to be traversed
  • Graceful handling of dangling symlinks (silently skipped)

Problem

The current walkDir implementation uses dirent.isFile() to check if an entry is a file. However, for symbolic links, dirent.isFile() returns false (the dirent type is "symbolic-link", not "file"), causing symlinks to be excluded from memory search indexing.

This is especially relevant for:

Solution

For entries that are symbolic links, we now call fs.stat() (which follows symlinks) to determine the actual target type:

if (entry.isSymbolicLink()) {
  try {
    const stat = await fs.stat(full);
    isDir = stat.isDirectory();
    isFile = stat.isFile();
  } catch {
    // Dangling symlink or inaccessible target - skip silently
    continue;
  }
}

Cross-platform notes

  • Linux/macOS: Works as expected
  • Windows: Creating symlinks may require elevated permissions, but reading existing symlinks works without special privileges
  • Dangling symlinks are gracefully skipped (no errors thrown)

Test plan

  • Added test: symlinked markdown files are discovered
  • Added test: files inside symlinked directories are discovered
  • Added test: dangling symlinks are skipped gracefully
  • Existing tests unaffected

Related: #2884

walkDir now follows symbolic links using fs.stat() to determine if
the target is a file or directory. This enables:

- Symlinked markdown files inside memory/ to be indexed
- Symlinked directories inside memory/ to be traversed
- Graceful handling of dangling symlinks (silently skipped)

Fixes an issue where dirent.isFile() returned false for symlinks,
causing them to be excluded from memory search indexing.

Cross-platform notes:
- Works on Linux/macOS/Windows (symlink support varies by platform)
- Windows may require elevated permissions to create symlinks,
  but reading existing symlinks works without special privileges
@gumadeiras
Copy link
Contributor

Symlinking outside of the workspace could introduce a number of problems in terms of security, recurrence, and scoping. Would it maybe be better to add support for custom search paths and force the user to add them manually?

Adding explicit, user‑configured search paths is safer than automatically following arbitrary symlinks

@kira-ariaki
Copy link
Contributor Author

Thanks for the feedback! You raise a valid point about security considerations.

A few thoughts:

  1. User intent is explicit — Symlinks inside memory/ are created by the user themselves, so following them respects an intentional configuration choice (similar to how git follows symlinks in the working tree).

  2. Scoped to workspace — We only follow symlinks discovered inside the existing memory/ directory, not arbitrary paths. The user must deliberately place a symlink there.

  3. Consistency with fix: Create memory directory and symlink identity files during workspace setup #2884 — The proposed workspace setup in fix: Create memory directory and symlink identity files during workspace setup #2884 creates symlinks for identity files. Without this fix, those symlinks would be silently ignored.

  4. Recursion safetyfs.stat() follows the symlink to its final target, so circular symlinks would fail with ELOOP and be gracefully skipped (same as dangling symlinks).

That said, I agree that explicit search paths could be a nice enhancement for power users who want more control. Would you prefer that as a follow-up PR, or should we gate symlink traversal behind a config flag (e.g., memorySearch.followSymlinks: true)?

@gumadeiras
Copy link
Contributor

  1. User intent is explicit — Symlinks inside memory/ are created by the user themselves, so following them respects an intentional configuration choice (similar to how git follows symlinks in the working tree).

Yes, but it can lead to unwanted situations where the user thinks it’s symlinking a single directory, but that directory could also contain symlinks, resulting in unwanted/insecure behavior. Or a simple attack where a symlink is created in the workspace to give it access to things outside of the workspace. We could think about hierarchical symlinking in terms of allowing depth=1, but that could become very ad hoc; I think having an explicit specification would be safer and simpler for a first pass at this feature

Let's put a pin on the symlinking for a couple of days and i'll get back on this after we've discussed implications

Could you do a follow up PR for explicit search paths? thanks!

kira-ariaki added a commit to kira-ariaki/moltbot that referenced this pull request Jan 28, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
gumadeiras pushed a commit to kira-ariaki/moltbot that referenced this pull request Jan 29, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to moltbot#2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
gumadeiras pushed a commit that referenced this pull request Jan 29, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to #2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
lawrence565 pushed a commit to lawrence565/moltbot that referenced this pull request Jan 29, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
HirokiKobayashi-R pushed a commit to HirokiKobayashi-R/moltbot that referenced this pull request Jan 29, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
mfgering pushed a commit to mfgering/mfg_moltbot that referenced this pull request Jan 29, 2026
Add a `paths` option to `memorySearch` config, allowing users to
explicitly specify additional directories or files to include in
memory search.

Follow-up to openclaw#2961 as suggested by @gumadeiras — instead of auto-following
symlinks (which has security implications), users can now explicitly
declare additional search paths.

- Add `memorySearch.paths` config option (array of strings)
- Paths can be absolute or relative (resolved from workspace)
- Directories are recursively scanned for `.md` files
- Single `.md` files can also be specified
- Paths from defaults and agent overrides are merged
- Added 4 test cases for listMemoryFiles
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.

2 participants