Repository navigation
fix: Create memory directory and symlink identity files during workspace setup - #2884
webdevtodayjason wants to merge 1 commit into
Conversation
…ace setup The memory search system expects files in ~/clawd/memory/ but workspace setup only created identity files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md) at the workspace root. This caused the memory index to report "no memory files found" even though identity files existed. Changes: - Create memory/ directory during ensureAgentWorkspace when ensureBootstrapFiles is true - Symlink identity files (SOUL.md, USER.md, AGENTS.md, IDENTITY.md) into memory/ so they are discoverable by the memory search indexer - Add memoryDir to the return type of ensureAgentWorkspace - Gracefully handle symlink creation failures (e.g., Windows without privileges) - Skip symlink creation if target file already exists (preserves user customizations) Fixes issue where clawdbot would claim "I have no memories" despite having identity files, because the memory search index was empty. Co-Authored-By: Claude Opus 4.5 <[email protected]>
| // Ensure memory/ directory exists and symlink identity files for memory search indexing | ||
| const memoryDir = path.join(dir, DEFAULT_MEMORY_DIR); | ||
| await fs.mkdir(memoryDir, { recursive: true }); |
There was a problem hiding this comment.
[P1] ensureAgentWorkspace({ ensureBootstrapFiles: true }) now always creates memory/ even when the workspace isn't brand-new. This can be an unexpected side effect (e.g., consumers calling this just to ensure identity files exist), and it also means the comment/test "does not create memory directory when ensureBootstrapFiles is false" is the only guard. If the intent is "create memory/ only for new workspaces" or "only if memory search is enabled", this should be gated on that condition rather than unconditional mkdir.
This matters when callers use ensureBootstrapFiles: true for reasons unrelated to memory indexing and don't expect new directories to appear.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.ts
Line: 180:182
Comment:
[P1] `ensureAgentWorkspace({ ensureBootstrapFiles: true })` now *always* creates `memory/` even when the workspace isn't brand-new. This can be an unexpected side effect (e.g., consumers calling this just to ensure identity files exist), and it also means the comment/test "does not create memory directory when ensureBootstrapFiles is false" is the only guard. If the intent is "create memory/ only for new workspaces" or "only if memory search is enabled", this should be gated on that condition rather than unconditional `mkdir`.
This matters when callers use `ensureBootstrapFiles: true` for reasons unrelated to memory indexing and don't expect new directories to appear.
How can I resolve this? If you propose a fix, please make it concise.| describe("ensureAgentWorkspace", () => { | ||
| it("creates memory directory with symlinks to identity files", async () => { | ||
| const tempDir = await makeTempWorkspace("moltbot-workspace-"); | ||
|
|
||
| const result = await ensureAgentWorkspace({ | ||
| dir: tempDir, | ||
| ensureBootstrapFiles: true, | ||
| }); | ||
|
|
||
| // Check memory directory was created | ||
| expect(result.memoryDir).toBe(path.join(tempDir, DEFAULT_MEMORY_DIR)); | ||
| const memoryDirStat = await fs.stat(result.memoryDir!); | ||
| expect(memoryDirStat.isDirectory()).toBe(true); | ||
|
|
||
| // Check symlinks exist in memory directory | ||
| const memoryFiles = await fs.readdir(result.memoryDir!); | ||
| expect(memoryFiles).toContain(DEFAULT_SOUL_FILENAME); | ||
| expect(memoryFiles).toContain(DEFAULT_USER_FILENAME); | ||
| expect(memoryFiles).toContain(DEFAULT_AGENTS_FILENAME); | ||
| expect(memoryFiles).toContain(DEFAULT_IDENTITY_FILENAME); | ||
|
|
||
| // Check symlinks point to correct files | ||
| const soulLink = await fs.readlink(path.join(result.memoryDir!, DEFAULT_SOUL_FILENAME)); | ||
| expect(soulLink).toBe(`../${DEFAULT_SOUL_FILENAME}`); | ||
| }); |
There was a problem hiding this comment.
[P1] This test assumes symlinks are created and that readlink() returns ../SOUL.md. On Windows (or environments without symlink privileges) the implementation intentionally swallows symlink failures, so this test will be flaky/fail there. Consider asserting "file exists OR symlink was skipped" (or skipping on Windows) and avoid hard-coding the readlink value.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.test.ts
Line: 59:83
Comment:
[P1] This test assumes symlinks are created and that `readlink()` returns `../SOUL.md`. On Windows (or environments without symlink privileges) the implementation intentionally swallows symlink failures, so this test will be flaky/fail there. Consider asserting "file exists OR symlink was skipped" (or skipping on Windows) and avoid hard-coding the readlink value.
How can I resolve this? If you propose a fix, please make it concise.| for (const { source, target } of identityFilesToSymlink) { | ||
| try { | ||
| await fs.access(target); | ||
| // Target already exists, skip | ||
| } catch { | ||
| // Target doesn't exist, create symlink | ||
| try { | ||
| const relativePath = path.relative(memoryDir, source); | ||
| await fs.symlink(relativePath, target); | ||
| } catch { | ||
| // Symlink creation failed (e.g., on Windows without privileges), skip silently | ||
| } |
There was a problem hiding this comment.
[P2] The symlink creation loop swallows all errors from both fs.access(target) and fs.symlink(...), including cases like permission denied to the directory, invalid paths, or partial failures. That can make workspace setup silently incomplete on non-Windows platforms too. At least consider narrowing the catches (e.g., only ignore EEXIST / EPERM / EACCES for symlink creation) or logging at verbose/debug level so users can diagnose why memory indexing isn't seeing identity files.
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.ts
Line: 192:203
Comment:
[P2] The symlink creation loop swallows *all* errors from both `fs.access(target)` and `fs.symlink(...)`, including cases like permission denied to the directory, invalid paths, or partial failures. That can make workspace setup silently incomplete on non-Windows platforms too. At least consider narrowing the catches (e.g., only ignore `EEXIST` / `EPERM` / `EACCES` for symlink creation) or logging at verbose/debug level so users can diagnose why memory indexing isn't seeing identity files.
How can I resolve this? If you propose a fix, please make it concise.| expect(result.memoryDir).toBeUndefined(); | ||
| const memoryDirPath = path.join(tempDir, DEFAULT_MEMORY_DIR); | ||
| await expect(fs.access(memoryDirPath)).rejects.toThrow(); | ||
| }); |
There was a problem hiding this comment.
[P2] await expect(fs.access(memoryDirPath)).rejects.toThrow() is quite broad: it will pass for any error (including transient permission issues) and doesn't verify it's actually missing. If you want to assert "directory does not exist", check for code === "ENOENT".
Prompt To Fix With AI
This is a comment left during a code review.
Path: src/agents/workspace.test.ts
Line: 93:96
Comment:
[P2] `await expect(fs.access(memoryDirPath)).rejects.toThrow()` is quite broad: it will pass for any error (including transient permission issues) and doesn't verify it's actually missing. If you want to assert "directory does not exist", check for `code === "ENOENT"`.
How can I resolve this? If you propose a fix, please make it concise.bfc1ccb to
f92900f
Compare
|
AI-assisted stale triage closure (2026-02-23). Closing this PR as stale/conflicted. Why this is being closed:
This is AI-closed housekeeping, not a rejection of the intended reliability improvement. If still relevant, please open a new PR from latest |
|
Adding instruction files that are always loaded into the agent context don't need to be in memory. |
Summary
memory/directory during workspace setup whenensureBootstrapFilesis truememory/so they are indexed by memory searchProblem
The memory search system looks for files in
~/clawd/memory/but workspace setup only created identity files at the workspace root. This caused:clawdbot memory statusto report "no memory files found"memory/directory and copy/symlink filesSolution
During
ensureAgentWorkspace()withensureBootstrapFiles: true:memory/subdirectoryTest plan
🤖 Generated with Claude Code
Greptile Overview
Greptile Summary
This PR updates workspace bootstrapping (
src/agents/workspace.ts) to create amemory/subdirectory duringensureAgentWorkspace({ ensureBootstrapFiles: true })and attempts to symlink the identity/bootstrap files (SOUL/USER/AGENTS/IDENTITY) into that directory so the memory search subsystem can index them. It also adds unit coverage insrc/agents/workspace.test.tsfor directory creation, symlink creation, and non-overwrite behavior.Overall, the change aligns workspace setup with other parts of the codebase (e.g., the memory CLI and internal scanner) which look for
memory/under the workspace directory. The main risks are around cross-platform symlink behavior and the fact that the newmemory/directory is created unconditionally wheneverensureBootstrapFilesis enabled.Confidence Score: 3/5
(5/5) You can turn off certain types of comments like style here!