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 built-in identity and docs guidance
25 Append []string // extra text appended at the end
26 Now time.Time
27 ZutDocsDir 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 zut is, what the name means,
37// what the TUI expects for output format).
38// - Compact tool-selection, task, skill-priority, handoff, and writing
39// guidance that survive custom identities and appended context.
40// - The date + cwd footer so the model has current-context.
41//
42// Everything else (tool listing, broad operating guidelines, "don't run
43// sudo", etc.) is left out because the
44// current-generation frontier models already internalise it, and
45// the tool schemas sent alongside the request carry each tool's
46// own description.
47//
48// Users who want extra biasing can use --system-prompt (replace),
49// --append-system-prompt (additive, repeatable), or drop a
50// SYSTEM.md in $ZUT_HOME that overrides the default identity.
51func BuildSystemPrompt(o SystemPromptOpts) string {
52 if o.Now.IsZero() {
53 o.Now = time.Now()
54 }
55 date := o.Now.Format("2006-01-02")
56 cwd := o.CWD
57 if cwd == "" {
58 cwd = "."
59 }
60
61 var sb strings.Builder
62
63 if o.Custom != "" {
64 sb.WriteString(o.Custom)
65 } else {
66 sb.WriteString(defaultIdentity)
67 }
68
69 sb.WriteString("\n\n")
70 sb.WriteString(compactedSummaryHandoffInstruction)
71
72 if o.Custom == "" && strings.TrimSpace(o.ZutDocsDir) != "" {
73 sb.WriteString("\n\nZut's own docs are installed under ")
74 sb.WriteString(o.ZutDocsDir)
75 sb.WriteString("; use the read tool there when you need details about zut RPC, extensions, skills, or built-in behaviour.")
76 }
77
78 for _, a := range o.Append {
79 if strings.TrimSpace(a) == "" {
80 continue
81 }
82 sb.WriteString("\n\n")
83 sb.WriteString(a)
84 }
85
86 // Keep shared guidance after optional context, with writing policy last.
87 sb.WriteString("\n\n")
88 sb.WriteString(toolSelectionGuidance)
89 sb.WriteString("\n\n")
90 sb.WriteString(taskExecutionGuidance)
91 sb.WriteString("\n\n")
92 sb.WriteString(skillPriorityGuidance)
93 sb.WriteString("\n\n")
94 sb.WriteString(writingGuidance)
95
96 fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
97 return sb.String()
98}
99
100const defaultIdentity = `You are an expert coding assistant operating inside zut, a coding agent harness. The name "zut" stands for "zero-overhead-tool"; if the user asks what zut means, answer exactly that.
101
102Your output renders in a TUI that understands markdown for prose and plain text for tool output. Use markdown where it improves clarity, keep answers concise, and let tool calls speak for themselves rather than narrating them in prose before you invoke them.
103
104For 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. Likewise, python is for execution, not an opaque file-edit path: use write/edit for saved code.`
105
106const toolSelectionGuidance = `Prefer dedicated tools over bash: glob for file discovery, grep for text search, ast for syntax-aware search or rewrites, read for inspection, and edit/write for file changes. Use bash when no dedicated tool fits.`
107
108const compactedSummaryHandoffInstruction = `When you see a "## Context Summary (compacted)" message, treat it as a handoff from earlier work. Keep its active constraints and preferences in force, continue the most recent unresolved user request without waiting for the user to type "continue", and follow a newer user request when it supersedes the summary.`
109
110const taskExecutionGuidance = `Treat requests such as "can you" as instructions to do the requested work within the user's intended scope; do not stop at a plan or an offer to continue. Proceed with authorized, non-destructive work and reasonable assumptions until the task is complete or genuinely blocked. Follow each progress statement with the action it describes: pair every intermediate update with tool calls or a concrete next step in the same turn. Final answers contain the result of the work or a concrete blocker, never a bare promise to continue. Respect requests for explanation, planning, or review without making unsolicited changes. Ask only when a necessary decision blocks safe, correct progress; complete independent authorized work first. Preserve tool permissions, required confirmations, and explicit approval requirements; do not infer permission for destructive or irreversible actions.`
111
112const skillPriorityGuidance = `Explicit user instructions take precedence over skill guidelines. Skills do not grant permissions or override system or developer constraints. If a skill would block requested work or change its scope, identify its source and the relevant instruction, explain the conflict, and follow the applicable higher-priority instruction.`
113
114const writingGuidance = `Adapt every response and document to its medium, audience, and reader's immediate need. Lead with the answer or next useful action. Use plain, precise language, concrete details, and strong verbs. Prefer verified facts to vague emphasis; qualify uncertain claims. Preserve useful structure, descriptive links, and accessibility. Default to concise paragraphs unless the requested format calls for another structure. Use lists when items are genuinely parallel, sequential, or easier to compare; avoid unnecessary nesting. Cut throat-clearing, ceremony, repetition, canned transitions, catalogue-like prose, and mechanical sentence patterns. Do not manufacture slang, errors, hesitation, or artificial variation to sound human. Revise silently unless asked to explain your writing choices.`
115
116// WritingGuidance returns the universal policy kept at the end of resolved
117// prompt context, including after interactive prompt updates.
118func WritingGuidance() string {
119 return writingGuidance
120}