Files
archie/internal/gateway/prompt.go
T
sam 44237b448b
deploy / plan (push) Successful in 6s
deploy / archied-image (push) Canceled after 0s
deploy / agent-image (push) Canceled after 0s
deploy / dist-zip (push) Canceled after 0s
ci/woodpecker/push/deploy Pipeline was canceled
deploy / gate (push) Canceled after 2m58s
refactor(prompts): every model prompt is a file in internal/prompts
2026-11-11 00:01:43 +11:00

96 lines
3.1 KiB
Go

package gateway
import (
"strings"
"time"
"github.com/samcharles93/archie-core/internal/prompts"
)
// ToolSummary is the capability metadata for one registered tool, as it is
// advertised to the model.
type ToolSummary struct {
Name string
Description string
}
// RepoEnv describes one managed repository for the chat prompt's <env> block.
type RepoEnv struct {
// FullName is the configured owner/name.
FullName string
// Forge is the forge host the repository lives on (forge.host). Empty
// means no forge is configured for the active identity.
Forge string
// DefaultBranch is the branch PRs target (repos[].base, "main" when
// unset) -- the branch the daemon actually uses, not a guess.
DefaultBranch string
}
// SystemPromptConfig holds the inputs for one rendered system prompt.
type SystemPromptConfig struct {
// Soul is the agent's SOUL identity text, rendered into the <soul> block.
Soul string
// Tools is the complete set of tools available for this turn.
Tools []ToolSummary
// Channel names the communication channel.
Channel string
Model string
SessionID string
// Page is the dashboard route the operator is on; empty outside the web
// channel.
Page string
// Now stamps the prompt's date.
Now time.Time
// Workspace is the directory the chat agent's file and shell tools are
// rooted at (chat.workspace). Empty means the agent has no rooted
// workspace: a real fact the prompt must say explicitly ("unknown") so the
// agent does not guess a path the daemon never granted it.
Workspace string
// Repos lists the repositories under management with their forge host and
// default branch. Rendered from live configuration (repos entries) so the
// agent knows its scope without probing the filesystem.
Repos []RepoEnv
// Operator is the display name of the person this deployment assists
// (chat.operator). Rendered so the agent knows the identity context it
// serves under; empty means unconfigured and must be said explicitly.
Operator string
// Memory is the rendered <memory> block body; empty omits the block.
Memory string
}
// promptData is the template execution context. It exists so the template
// sees a pre-formatted date and pre-flattened tool metadata rather than
// calling methods during rendering.
type promptData struct {
SystemPromptConfig
Date string
ProductGuide string
}
// BuildSystemPrompt renders the chat agent's system prompt.
func BuildSystemPrompt(cfg SystemPromptConfig) string {
tools := make([]ToolSummary, len(cfg.Tools))
for i, tool := range cfg.Tools {
tools[i] = ToolSummary{
Name: strings.Join(strings.Fields(tool.Name), " "),
Description: strings.Join(strings.Fields(tool.Description), " "),
}
}
data := promptData{
Soul: cfg.Soul,
Tools: tools,
Channel: cfg.Channel,
Model: cfg.Model,
SessionID: cfg.SessionID,
Page: cfg.Page,
Now: cfg.Now,
Date: cfg.Now.Format("2006-01-02"),
Workspace: cfg.Workspace,
Repos: cfg.Repos,
Operator: cfg.Operator,
Memory: cfg.Memory,
ProductGuide: prompts.ProductGuide(),
}
return prompts.ChatSystem(data)
}