mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-17 06:14:48 +00:00
fix(tools): hint model when shell commands target DB-backed memory files
Memory files (MEMORY.md, memory/*.md) are stored in PostgreSQL, not on disk. When the model uses exec to run cat/ls/grep/find on memory paths, short-circuit with a hint to use memory_search or memory_get instead. Also append [Source: database, not filesystem] to read_file and list_files results served from the memory interceptor.
This commit is contained in:
1 parent
99720892a7
commit
7ba3a5115a
4 files changed
+54
-2
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package tools
|
||||
|
||||
import "strings"
|
||||
|
||||
// memoryHintPrefixes are shell commands that read/list/search filesystem content.
|
||||
// If these target memory paths, the model should use dedicated memory tools instead.
|
||||
var memoryHintPrefixes = []string{
|
||||
"cat ", "head ", "tail ", "less ", "more ",
|
||||
"grep ", "rg ", "ag ",
|
||||
"find ", "ls ", "wc ",
|
||||
}
|
||||
|
||||
// memoryPathTokens are path fragments indicating memory file access.
|
||||
var memoryPathTokens = []string{
|
||||
"MEMORY.md", "memory.md", "memory/",
|
||||
}
|
||||
|
||||
// MaybeMemoryExecHint checks if a shell command targets memory files
|
||||
// (which live in the database, not on disk) and returns an LLM hint.
|
||||
// Returns empty string if no memory path detected.
|
||||
func MaybeMemoryExecHint(command string) string {
|
||||
trimmed := strings.TrimSpace(command)
|
||||
if trimmed == "" {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Check if command uses a filesystem read/list/search binary.
|
||||
hasReadCmd := false
|
||||
for _, prefix := range memoryHintPrefixes {
|
||||
if strings.HasPrefix(trimmed, prefix) {
|
||||
hasReadCmd = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !hasReadCmd {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Check if the command references a memory path.
|
||||
for _, token := range memoryPathTokens {
|
||||
if strings.Contains(trimmed, token) {
|
||||
return "[HINT] Memory files are in the database, not on disk. Use memory_search or memory_get tool instead."
|
||||
}
|
||||
}
|
||||
|
||||
return ""
|
||||
}
|
||||
Reference in new issue
Block a user