v0.0.15 3ff6d9e

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 = `{
26  "type":"object",
27  "properties":{
28    "path":{"type":"string","description":"Path to the file to write (relative or absolute)"},
29    "content":{"type":"string","description":"File contents. Overwrites any existing file."}
30  },
31  "required":["path","content"],
32  "additionalProperties":false
33}`
34
35func (t *WriteTool) Name() string { return "write" }
36func (t *WriteTool) Description() string {
37	return "Write content to a file. Creates parent directories. Overwrites existing files."
38}
39func (t *WriteTool) Schema() json.RawMessage { return json.RawMessage(writeSchema) }
40
41func (t *WriteTool) Execute(ctx context.Context, raw json.RawMessage, progress func(string)) (core.ToolResult, error) {
42	var a writeArgs
43	if err := json.Unmarshal(raw, &a); err != nil {
44		return core.ToolResult{}, fmt.Errorf("invalid args: %w", err)
45	}
46	if a.Path == "" {
47		return core.ToolResult{}, fmt.Errorf("path is required")
48	}
49	path := resolvePath(t.CWD, a.Path)
50	if err := t.Sandbox.CheckPath(path); err != nil {
51		return core.ToolResult{}, err
52	}
53
54	if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
55		return core.ToolResult{}, err
56	}
57	if err := os.WriteFile(path, []byte(a.Content), 0o644); err != nil {
58		return core.ToolResult{}, err
59	}
60
61	msg := fmt.Sprintf("wrote %d bytes to %s", len(a.Content), a.Path)
62	return core.ToolResult{
63		Content: []provider.Content{provider.TextBlock{Text: msg}},
64		Details: map[string]any{"path": path, "bytes": len(a.Content)},
65	}, nil
66}

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