Mistral provider adapter with streaming, tool calls (single-chunk pattern), stop reason inference, model listing, capabilities, and JSON output support. Tool system: bash (7 security checks, shell alias harvesting for bash/zsh/fish), file ops (read, write, edit, glob, grep, ls). Alias harvesting collects 300+ aliases from user's shell config. Engine agentic loop: stream → tool execution → re-query → until done. Tool gating on model capabilities. Max turns safety limit. CLI pipe mode: echo "prompt" | gnoma streams response to stdout. Flags: --provider, --model, --system, --api-key, --max-turns, --verbose, --version. Provider interface expanded: Models(), DefaultModel(), Capabilities (ToolUse, JSONOutput, Vision, Thinking, ContextWindow, MaxOutput), ResponseFormat with JSON schema support. Live verified: text streaming + tool calling with devstral-small. 117 tests across 8 packages, 10MB binary.
69 lines
1.8 KiB
Go
69 lines
1.8 KiB
Go
package fs
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"somegit.dev/Owlibou/gnoma/internal/tool"
|
|
)
|
|
|
|
const writeToolName = "fs.write"
|
|
|
|
var writeParams = json.RawMessage(`{
|
|
"type": "object",
|
|
"properties": {
|
|
"path": {
|
|
"type": "string",
|
|
"description": "Absolute path to the file to write"
|
|
},
|
|
"content": {
|
|
"type": "string",
|
|
"description": "Content to write to the file"
|
|
}
|
|
},
|
|
"required": ["path", "content"]
|
|
}`)
|
|
|
|
type WriteTool struct{}
|
|
|
|
func NewWriteTool() *WriteTool { return &WriteTool{} }
|
|
|
|
func (t *WriteTool) Name() string { return writeToolName }
|
|
func (t *WriteTool) Description() string { return "Write content to a file, creating parent directories as needed" }
|
|
func (t *WriteTool) Parameters() json.RawMessage { return writeParams }
|
|
func (t *WriteTool) IsReadOnly() bool { return false }
|
|
func (t *WriteTool) IsDestructive() bool { return false }
|
|
|
|
type writeArgs struct {
|
|
Path string `json:"path"`
|
|
Content string `json:"content"`
|
|
}
|
|
|
|
func (t *WriteTool) Execute(_ context.Context, args json.RawMessage) (tool.Result, error) {
|
|
var a writeArgs
|
|
if err := json.Unmarshal(args, &a); err != nil {
|
|
return tool.Result{}, fmt.Errorf("fs.write: invalid args: %w", err)
|
|
}
|
|
if a.Path == "" {
|
|
return tool.Result{}, fmt.Errorf("fs.write: path required")
|
|
}
|
|
|
|
// Create parent directories
|
|
dir := filepath.Dir(a.Path)
|
|
if err := os.MkdirAll(dir, 0o755); err != nil {
|
|
return tool.Result{Output: fmt.Sprintf("Error creating directory: %v", err)}, nil
|
|
}
|
|
|
|
if err := os.WriteFile(a.Path, []byte(a.Content), 0o644); err != nil {
|
|
return tool.Result{Output: fmt.Sprintf("Error writing file: %v", err)}, nil
|
|
}
|
|
|
|
return tool.Result{
|
|
Output: fmt.Sprintf("Wrote %d bytes to %s", len(a.Content), a.Path),
|
|
Metadata: map[string]any{"bytes_written": len(a.Content), "path": a.Path},
|
|
}, nil
|
|
}
|