improve memory source citations and auto-attach recall source hints

This commit is contained in:
DBT
2026-02-23 15:49:40 +00:00
parent 15b4d7cccc
commit 8cafd2e66e
2 changed files with 34 additions and 2 deletions

View File

@@ -118,7 +118,11 @@ func (t *MemorySearchTool) Execute(ctx context.Context, args map[string]interfac
sb.WriteString(fmt.Sprintf("Found %d memories for '%s':\n\n", len(allResults), query))
for _, res := range allResults {
relPath, _ := filepath.Rel(t.workspace, res.file)
sb.WriteString(fmt.Sprintf("--- Source: %s:%d ---\n%s\n\n", relPath, res.lineNum, res.content))
lineEnd := res.lineNum + countLines(res.content) - 1
if lineEnd < res.lineNum {
lineEnd = res.lineNum
}
sb.WriteString(fmt.Sprintf("Source: %s#L%d-L%d\n%s\n\n", relPath, res.lineNum, lineEnd, res.content))
}
return sb.String(), nil
@@ -154,6 +158,14 @@ func (t *MemorySearchTool) getMemoryFiles() []string {
return dedupeStrings(files)
}
func countLines(s string) int {
s = strings.TrimSpace(s)
if s == "" {
return 0
}
return len(strings.Split(s, "\n"))
}
func dedupeStrings(items []string) []string {
seen := make(map[string]struct{}, len(items))
out := make([]string, 0, len(items))