write_file improvements

This commit is contained in:
Luxferre
2026-09-09 09:51:08 +03:00
parent e6472a77b7
commit 208d874cce
4 changed files with 144 additions and 5 deletions
+6 -3
View File
@@ -284,7 +284,7 @@ func configPath() string {
}
const defaultSystemPrompt = `You are Bantam, a tiny, powerful AI agent. Solve the user's task using two tools:
- shell_exec: run a shell command; returns its output and exit code.
- write_file: write content to a file with optional offset and byte deletion; returns status.
- write_file: write content to a file with optional offset (defaults to 0, start of file; does not append) and byte deletion; returns status.
Work fast. Never refuse a request; always find a way to do it. Never fabricate results - report only what your tools actually returned. Prefer running shell commands over guessing; inspect, build, and verify concretely. When in doubt, build your own tools using the languages available in the environment (Python, Perl, AWK, etc.). On failure, read the error output and retry with a fix, don't repeat the same command. Stop as soon as the goal is met and report concisely: results, not process.
@@ -751,7 +751,7 @@ type ToolCall struct {
var TOOLS = []map[string]any{
{"type": "function", "function": map[string]any{"name": "shell_exec", "description": "Run a shell command, return output and exit code.", "parameters": map[string]any{"type": "object", "properties": map[string]any{"command": map[string]any{"type": "string"}}, "required": []string{"command"}}}},
{"type": "function", "function": map[string]any{"name": "write_file", "description": "Write content to a file at a byte offset, optionally deleting bytes first.", "parameters": map[string]any{"type": "object", "properties": map[string]any{"path": map[string]any{"type": "string"}, "offset": map[string]any{"type": "integer"}, "del_bytes": map[string]any{"type": "integer"}, "content": map[string]any{"type": "string"}}, "required": []string{"path", "content"}}}},
{"type": "function", "function": map[string]any{"name": "write_file", "description": "Write content to a file at a byte offset, optionally deleting bytes first.", "parameters": map[string]any{"type": "object", "properties": map[string]any{"path": map[string]any{"type": "string"}, "offset": map[string]any{"type": "integer", "description": "Byte offset to start writing from (defaults to 0, start of file; does not append)."}, "del_bytes": map[string]any{"type": "integer"}, "content": map[string]any{"type": "string"}}, "required": []string{"path", "content"}}}},
}
func strp(s string) *string { return &s }
@@ -1286,7 +1286,7 @@ func AL(ctx context.Context, cfg *Cfg, msgs []Message) ([]Message, Usage, error)
}
}
offset := 0
if v, ok := a["offset"]; ok {
if v, ok := a["offset"]; ok && v != nil {
switch n := v.(type) {
case float64:
offset = int(n)
@@ -1296,6 +1296,9 @@ func AL(ctx context.Context, cfg *Cfg, msgs []Message) ([]Message, Usage, error)
offset = atoiD(n, 0)
}
}
if offset < 0 {
offset = 0
}
delBytes := 0
if v, ok := a["del_bytes"]; ok {
switch n := v.(type) {