zot/packages/agent/systemprompt.go
patriceckhart fa7d8d8be5 refactor: split source into packages/{provider,core,tui,agent}
Single Go module, four top-level packages under packages/. Import
paths become github.com/patriceckhart/zot/packages/<name>; downstream
consumers can depend on individual packages without pulling the rest.

Layout:
  packages/provider/     LLM clients + catalog
  packages/provider/auth/ credential store + OAuth + login server
  packages/core/         agent loop, sessions, cost
  packages/tui/          terminal toolkit + chat view
  packages/agent/        CLI wiring, system prompt
    extensions/ extproto/ modes/ tools/ skills/ swarm/
    sdk/  (was pkg/zotcore, package renamed zotcore -> sdk)
    ext/  (was pkg/zotext, package renamed zotext -> ext)

internal/ and pkg/ removed. The internal/assets logo moved into
packages/provider/auth/assets.

Public Go SDK identifiers renamed:
  pkg/zotcore (package zotcore) -> packages/agent/sdk (package sdk)
  pkg/zotext  (package zotext)  -> packages/agent/ext (package ext)

This breaks Go-based extensions and embedders; the JSON wire protocol
for extensions and RPC is unchanged, so non-Go extensions, already-
built extension binaries, and zot rpc consumers are unaffected.

Docs, examples, and the built-in write-zot-extension skill updated
for the new paths and identifiers. Shadow-bug fixes in code samples
(ext := ext.New -> e := ext.New).
2026-05-27 09:07:15 +02:00

89 lines
3.1 KiB
Go

package agent
import (
"fmt"
"strings"
"time"
)
// ToolSummary is a name+one-line description. Kept as part of the
// public opts type for backwards compatibility with callers that
// still pass tool summaries in; the default prompt no longer lists
// them because the provider already advertises tools in the request
// body's tools[] array, so listing them again in prose is pure
// duplication.
type ToolSummary struct {
Name string
Description string
}
// SystemPromptOpts configures BuildSystemPrompt.
type SystemPromptOpts struct {
CWD string
Tools []ToolSummary
Custom string // if set, replaces the default identity entirely
Append []string // extra text appended at the end
Now time.Time
ZotDocsDir string
}
// BuildSystemPrompt constructs the system prompt.
//
// Design note: kept intentionally small. Every byte here is part of
// the cached prefix on every request, so bloat is cumulatively
// expensive. We ship only:
//
// - A one-paragraph identity (who zot is, what the name means,
// what the TUI expects for output format).
// - The date + cwd footer so the model has current-context.
//
// Everything else (tool listing, operating guidelines, "don't run
// sudo", "prefer edit over write", etc.) is left out because the
// current-generation frontier models already internalise it, and
// the tool schemas sent alongside the request carry each tool's
// own description.
//
// Users who want extra biasing can use --system-prompt (replace),
// --append-system-prompt (additive, repeatable), or drop a
// SYSTEM.md in $ZOT_HOME that overrides the default identity.
func BuildSystemPrompt(o SystemPromptOpts) string {
if o.Now.IsZero() {
o.Now = time.Now()
}
date := o.Now.Format("2006-01-02")
cwd := o.CWD
if cwd == "" {
cwd = "."
}
var sb strings.Builder
if o.Custom != "" {
sb.WriteString(o.Custom)
} else {
sb.WriteString(defaultIdentity)
}
if strings.TrimSpace(o.ZotDocsDir) != "" {
sb.WriteString("\n\nZot's own docs are installed under ")
sb.WriteString(o.ZotDocsDir)
sb.WriteString("; use the read tool there when you need details about zot RPC, extensions, skills, or built-in behaviour.")
}
for _, a := range o.Append {
if strings.TrimSpace(a) == "" {
continue
}
sb.WriteString("\n\n")
sb.WriteString(a)
}
fmt.Fprintf(&sb, "\n\nCurrent date: %s\nCurrent working directory: %s\n", date, cwd)
return sb.String()
}
const 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.
Your 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.
When changing file contents, prefer the edit tool for in-place changes and the write tool for creating or fully replacing files. Do not use bash with cat/echo/sed/tee redirections to mutate files; those changes render as opaque shell output while edit renders as a readable diff.`