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

Function formatSystemInstructions

coderd/x/chatd/instruction.go:18–60  ·  view source on GitHub ↗

formatSystemInstructions builds the block from agent metadata and zero or more context-file parts. Non-context-file parts in the slice are silently skipped.

(
	operatingSystem, directory string,
	parts []codersdk.ChatMessagePart,
)

Source from the content-addressed store, hash-verified

16// agent metadata and zero or more context-file parts. Non-context-file
17// parts in the slice are silently skipped.
18func formatSystemInstructions(
19 operatingSystem, directory string,
20 parts []codersdk.ChatMessagePart,
21) string {
22 hasContent := false
23 for _, part := range parts {
24 if part.Type == codersdk.ChatMessagePartTypeContextFile && part.ContextFileContent != "" {
25 hasContent = true
26 break
27 }
28 }
29 if !hasContent && operatingSystem == "" && directory == "" {
30 return ""
31 }
32
33 var b strings.Builder
34 _, _ = b.WriteString("<workspace-context>\n")
35 if operatingSystem != "" {
36 _, _ = b.WriteString("Operating System: ")
37 _, _ = b.WriteString(operatingSystem)
38 _, _ = b.WriteString("\n")
39 }
40 if directory != "" {
41 _, _ = b.WriteString("Working Directory: ")
42 _, _ = b.WriteString(directory)
43 _, _ = b.WriteString("\n")
44 }
45 for _, part := range parts {
46 if part.Type != codersdk.ChatMessagePartTypeContextFile || part.ContextFileContent == "" {
47 continue
48 }
49 _, _ = b.WriteString("\nSource: ")
50 _, _ = b.WriteString(part.ContextFilePath)
51 if part.ContextFileTruncated {
52 _, _ = b.WriteString(" (truncated to 64KiB)")
53 }
54 _, _ = b.WriteString("\n")
55 _, _ = b.WriteString(part.ContextFileContent)
56 _, _ = b.WriteString("\n")
57 }
58 _, _ = b.WriteString("</workspace-context>")
59 return b.String()
60}
61
62// latestContextAgentID returns the most recent workspace-agent ID seen
63// on any persisted context-file part, including the skill-only sentinel.

Callers 3

Calls 2

WriteStringMethod · 0.80
StringMethod · 0.45

Tested by 1