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 // when CustomSet, replaces the built-in identity and docs guidance
25 CustomSet bool // preserves an intentionally empty custom prompt
26 Append []string // extra text appended at the end
27 Now time.Time
28 ZotDocsDir string
29}
30
31// BuildSystemPrompt constructs the system prompt.
32//
33// Design note: kept intentionally small. Every byte here is part of
34// the cached prefix on every request, so bloat is cumulatively
35// expensive. We ship only:
36//
37// - A one-paragraph identity (who zot is, what the name means,
38// what the TUI expects for output format).
39// - The date + cwd footer so the model has current-context.
40//
41// Everything else (tool listing, operating guidelines, "don't run
42// sudo", "prefer edit over write", etc.) is left out because the
43// current-generation frontier models already internalise it, and
44// the tool schemas sent alongside the request carry each tool's
45// own description.
46//
47// Users who want extra biasing can use --system-prompt (replace),
48// --append-system-prompt (additive, repeatable), or drop a
49// SYSTEM.md in $ZOT_HOME that overrides the default identity.
50func BuildSystemPrompt(o SystemPromptOpts) string {
51 if o.Now.IsZero() {
52 o.Now = time.Now()
53 }
54 date := o.Now.Format("2006-01-02")
55 cwd := o.CWD
56 if cwd == "" {
57 cwd = "."
58 }
59
60 var sb strings.Builder
61
62 if o.CustomSet || o.Custom != "" {
63 sb.WriteString(o.Custom)
64 } else {
65 sb.WriteString(defaultIdentity)
66 if strings.TrimSpace(o.ZotDocsDir) != "" {
67 sb.WriteString("\n\nZot's own docs are installed under ")
68 sb.WriteString(o.ZotDocsDir)
69 sb.WriteString("; use the read tool there when you need details about zot RPC, extensions, skills, or built-in behaviour.")
70 }
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.`