mirror of
https://github.com/YspCoder/clawgo.git
synced 2026-04-15 03:57:30 +08:00
improve memory source citations and auto-attach recall source hints
This commit is contained in:
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user