v0.0.21 4dde650

systemprompt.go RawHistoryFolder

1package agent
2
3import (
4	"fmt"
5	"strings"
6	"time"
7)
8
9// ToolSummary is a name+one-line description, used when rendering the
10// "available tools" section of the system prompt.
11type ToolSummary struct {
12	Name        string
13	Description string
14}
15
16// SystemPromptOpts configures BuildSystemPrompt.
17type SystemPromptOpts struct {
18	CWD    string
19	Tools  []ToolSummary
20	Custom string   // if set, replaces the default identity/guidelines sections
21	Append []string // extra text appended at the end
22	Now    time.Time
23}
24
25// BuildSystemPrompt constructs the system prompt.
26func BuildSystemPrompt(o SystemPromptOpts) string {
27	if o.Now.IsZero() {
28		o.Now = time.Now()
29	}
30	date := o.Now.Format("2006-01-02")
31	cwd := o.CWD
32	if cwd == "" {
33		cwd = "."
34	}
35
36	var sb strings.Builder
37
38	if o.Custom != "" {
39		sb.WriteString(o.Custom)
40	} else {
41		sb.WriteString(defaultIdentity)
42		sb.WriteString("\n\n")
43		sb.WriteString(renderToolsSection(o.Tools))
44		sb.WriteString("\n")
45		sb.WriteString(defaultGuidelines)
46	}
47
48	for _, a := range o.Append {
49		if strings.TrimSpace(a) == "" {
50			continue
51		}
52		sb.WriteString("\n\n")
53		sb.WriteString(a)
54	}
55
56	fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
57	return sb.String()
58}
59
60func renderToolsSection(tools []ToolSummary) string {
61	if len(tools) == 0 {
62		return "No tools are available in this session."
63	}
64	var sb strings.Builder
65	sb.WriteString("You have the following tools available:\n")
66	for _, t := range tools {
67		fmt.Fprintf(&sb, "- %s: %s\n", t.Name, t.Description)
68	}
69	return sb.String()
70}
71
72const defaultIdentity = `You are zot, a lightweight terminal coding assistant.
73You help a developer by reading files, writing files, editing files, and running shell commands.
74You are concise. You explain your plan briefly, then act. You do not apologize or hedge.`
75
76const defaultGuidelines = `Operating guidelines:
77- Prefer "edit" over "write" for existing files. Always read a file before editing it.
78- Before running "bash", explain what the command will do in one short sentence.
79- Avoid destructive commands (rm -rf, dropping tables, force-pushing, etc.) unless the user explicitly asks.
80- Keep shell commands non-interactive (pass -y / --yes where needed; pipe "yes" if required).
81- When unsure about a file's contents or structure, read it first rather than guess.
82- When you are done, reply with a short summary of what you changed and any commands the user should run.`

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