MCPcopy Index your code
hub / github.com/coder/coder / resolveDeploymentSystemPrompt

Method resolveDeploymentSystemPrompt

coderd/x/chatd/chatd.go:9185–9211  ·  view source on GitHub ↗

resolveDeploymentSystemPrompt builds the deployment-level system prompt from the built-in default and the admin-configured custom prompt stored in site_configs.

(ctx context.Context)

Source from the content-addressed store, hash-verified

9183// prompt from the built-in default and the admin-configured custom
9184// prompt stored in site_configs.
9185func (p *Server) resolveDeploymentSystemPrompt(ctx context.Context) string {
9186 config, err := p.db.GetChatSystemPromptConfig(ctx)
9187 if err != nil {
9188 // Fail open: use the built-in default so chats always have
9189 // some system guidance.
9190 p.logger.Error(ctx, "failed to fetch chat system prompt configuration, using default", slog.Error(err))
9191 return DefaultSystemPrompt
9192 }
9193
9194 sanitizedCustom := SanitizePromptText(config.ChatSystemPrompt)
9195 if sanitizedCustom == "" && strings.TrimSpace(config.ChatSystemPrompt) != "" {
9196 p.logger.Warn(ctx, "custom system prompt became empty after sanitization, omitting custom portion")
9197 }
9198
9199 var parts []string
9200 if config.IncludeDefaultSystemPrompt {
9201 parts = append(parts, DefaultSystemPrompt)
9202 }
9203 if sanitizedCustom != "" {
9204 parts = append(parts, sanitizedCustom)
9205 }
9206 result := strings.Join(parts, "\n\n")
9207 if result == "" {
9208 p.logger.Warn(ctx, "resolved system prompt is empty, no system prompt will be injected into chats")
9209 }
9210 return result
9211}
9212
9213// resolveUserPrompt fetches the user's custom chat prompt from the
9214// database and wraps it in <user-instructions> tags. Returns empty

Callers 2

CreateChatMethod · 0.95

Calls 3

SanitizePromptTextFunction · 0.85
ErrorMethod · 0.45

Tested by

no test coverage detected