v0.0.49 f8c309e

write.go RawHistoryFolder

1package tools
2
3import (
4	"context"
5	"encoding/json"
6	"fmt"
7	"os"
8	"path/filepath"
9
10	"github.com/patriceckhart/zot/internal/core"
11	"github.com/patriceckhart/zot/internal/provider"
12)
13
14// WriteTool writes content to a file, creating parent directories.
15type WriteTool struct {
16	CWD     string
17	Sandbox *Sandbox
18}
19
20type writeArgs struct {
21	Path    string `json:"path"`
22	Content string `json:"content"`
23}
24
25const writeSchema = `{"type":"object","properties":{"path":{"type":"string"},"content":{"type":"string"}},"required":["path","content"]}`
26
27func (t *WriteTool) Name() string { return "write" }
28func (t *WriteTool) Description() string {
29	return "Write a file. Creates parent dirs. Overwrites."
30}
31func (t *WriteTool) Schema() json.RawMessage { return json.RawMessage(writeSchema) }
32
33func (t *WriteTool) Execute(ctx context.Context, raw json.RawMessage, progress func(string)) (core.ToolResult, error) {
34	var a writeArgs
35	if err := json.Unmarshal(raw, &a); err != nil {
36		return core.ToolResult{}, fmt.Errorf("invalid args: %w", err)
37	}
38	if a.Path == "" {
39		return core.ToolResult{}, fmt.Errorf("path is required")
40	}
41	path := resolvePath(t.CWD, a.Path)
42	if err := t.Sandbox.CheckPath(path); err != nil {
43		return core.ToolResult{}, err
44	}
45
46	if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
47		return core.ToolResult{}, err
48	}
49	if err := os.WriteFile(path, []byte(a.Content), 0o644); err != nil {
50		return core.ToolResult{}, err
51	}
52
53	msg := fmt.Sprintf("wrote %d bytes to %s", len(a.Content), a.Path)
54	return core.ToolResult{
55		Content: []provider.Content{provider.TextBlock{Text: msg}},
56		Details: map[string]any{"path": path, "bytes": len(a.Content)},
57	}, nil
58}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 476

↑↓ moveenter openesc close