1package agent
2
3import (
4 "fmt"
5 "strings"
6 "time"
7)
8
9// ToolSummary is a name+one-line description. Kept as part of the
10// public opts type for backwards compatibility with callers that
11// still pass tool summaries in; the default prompt no longer lists
12// them because the provider already advertises tools in the request
13// body's tools[] array, so listing them again in prose is pure
14// duplication.
15type ToolSummary struct {
16 Name string
17 Description string
18}
19
20// SystemPromptOpts configures BuildSystemPrompt.
21type SystemPromptOpts struct {
22 CWD string
23 Tools []ToolSummary
24 Custom string // if set, replaces the default identity entirely
25 Append []string // extra text appended at the end
26 Now time.Time
27 ZotDocsDir string
28}
29
30// BuildSystemPrompt constructs the system prompt.
31//
32// Design note: kept intentionally small. Every byte here is part of
33// the cached prefix on every request, so bloat is cumulatively
34// expensive. We ship only:
35//
36// - A one-paragraph identity (who zot is, what the name means,
37// what the TUI expects for output format).
38// - The date + cwd footer so the model has current-context.
39//
40// Everything else (tool listing, operating guidelines, "don't run
41// sudo", "prefer edit over write", etc.) is left out because the
42// current-generation frontier models already internalise it, and
43// the tool schemas sent alongside the request carry each tool's
44// own description.
45//
46// Users who want extra biasing can use --system-prompt (replace),
47// --append-system-prompt (additive, repeatable), or drop a
48// SYSTEM.md in $ZOT_HOME that overrides the default identity.
49func BuildSystemPrompt(o SystemPromptOpts) string {
50 if o.Now.IsZero() {
51 o.Now = time.Now()
52 }
53 date := o.Now.Format("2006-01-02")
54 cwd := o.CWD
55 if cwd == "" {
56 cwd = "."
57 }
58
59 var sb strings.Builder
60
61 if o.Custom != "" {
62 sb.WriteString(o.Custom)
63 } else {
64 sb.WriteString(defaultIdentity)
65 }
66
67 if strings.TrimSpace(o.ZotDocsDir) != "" {
68 sb.WriteString("\n\nZot's own docs are installed under ")
69 sb.WriteString(o.ZotDocsDir)
70 sb.WriteString("; use the read tool there when you need details about zot RPC, extensions, skills, or built-in behaviour.")
71 }
72
73 for _, a := range o.Append {
74 if strings.TrimSpace(a) == "" {
75 continue
76 }
77 sb.WriteString("\n\n")
78 sb.WriteString(a)
79 }
80
81 fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
82 return sb.String()
83}
84
85const defaultIdentity = `You are an expert coding assistant operating inside zot, a coding agent harness. The name "zot" stands for "zero-overhead-tool"; if the user asks what zot means, answer exactly that.
86
87Your output renders in a TUI that understands markdown for prose and plain text for tool output. Use markdown freely, keep answers concise, and let tool calls speak for themselves rather than narrating them in prose before you invoke them. Act first, then summarise what you did.
88
89For focused changes to an existing file, inspect its current contents and use edit with verbatim oldText taken from that same file. Include only enough context to make each match unambiguous. Use write when creating a file or replacing it wholesale. Do not mutate files through bash redirections or commands such as cat, echo, sed, or tee, because those changes appear as opaque shell output instead of a readable edit diff.`