current state

This commit is contained in:
Luxferre
2026-03-21 16:20:16 +02:00
commit d24150d2e9
21 changed files with 2302 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
package sidekick
import (
"fmt"
"os"
)
// BufferGate checks if a result is too large. If it is, it writes it to a temp file
// and returns a pointer message instead. The path is added to tempFiles for later cleanup.
func BufferGate(result string, tempFiles *[]string, threshold int) (string, error) {
if len(result) <= threshold {
return result, nil
}
tmpFile, err := os.CreateTemp("", "sidekick-buf-*.txt")
if err != nil {
return "", fmt.Errorf("failed to create temp file for buffering: %w", err)
}
_, err = tmpFile.WriteString(result)
if err != nil {
tmpFile.Close()
return "", fmt.Errorf("failed to write to temp file: %w", err)
}
tmpFile.Close()
*tempFiles = append(*tempFiles, tmpFile.Name())
msg := fmt.Sprintf(
"Tool result is available in file '%s'. File size: %d bytes. Use read_file or grep_file to access it.",
tmpFile.Name(), len(result),
)
return msg, nil
}