feat(memory): add explicit paths config for memory search

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
This commit is contained in:
Kira
2026-01-28 17:08:17 -05:00
committed by Gustavo Madeira Santana
parent b717724275
commit 0fd9d3abd1
9 changed files with 13334 additions and 5 deletions

View File

@@ -60,7 +60,10 @@ async function walkDir(dir: string, files: string[]) {
}
}
export async function listMemoryFiles(workspaceDir: string): Promise<string[]> {
export async function listMemoryFiles(
workspaceDir: string,
additionalPaths?: string[],
): Promise<string[]> {
const result: string[] = [];
const memoryFile = path.join(workspaceDir, "MEMORY.md");
const altMemoryFile = path.join(workspaceDir, "memory.md");
@@ -70,6 +73,19 @@ export async function listMemoryFiles(workspaceDir: string): Promise<string[]> {
if (await exists(memoryDir)) {
await walkDir(memoryDir, result);
}
// Include files from additional explicit paths
if (additionalPaths && additionalPaths.length > 0) {
for (const p of additionalPaths) {
const resolved = path.isAbsolute(p) ? p : path.resolve(workspaceDir, p);
if (!(await exists(resolved))) continue;
const stat = await fs.stat(resolved);
if (stat.isDirectory()) {
await walkDir(resolved, result);
} else if (stat.isFile() && resolved.endsWith(".md")) {
result.push(resolved);
}
}
}
if (result.length <= 1) return result;
const seen = new Set<string>();
const deduped: string[] = [];