mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 14:28:27 +00:00
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:
committed by
Gustavo Madeira Santana
parent
b717724275
commit
0fd9d3abd1
@@ -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[] = [];
|
||||
|
||||
Reference in New Issue
Block a user