@@ -93,11 +93,28 @@ func getAgentMarkdown(c *gin.Context) {
9393 c .JSON (http .StatusBadRequest , gin.H {"error" : "persona required" })
9494 return
9595 }
96+ md , err := renderAgentMarkdownContent (persona )
97+ if err != nil {
98+ if strings .Contains (strings .ToLower (err .Error ()), "not found" ) {
99+ c .JSON (http .StatusNotFound , gin.H {"error" : "persona not found" })
100+ return
101+ }
102+ c .JSON (http .StatusInternalServerError , gin.H {"error" : fmt .Sprintf ("failed to render agent markdown: %v" , err )})
103+ return
104+ }
105+ c .Data (http .StatusOK , "text/markdown; charset=utf-8" , []byte (md ))
106+ }
107+
108+ // renderAgentMarkdownContent builds the markdown content for a given agent persona
109+ // by reading its YAML definition from the configured agents directory.
110+ func renderAgentMarkdownContent (persona string ) (string , error ) {
111+ if strings .TrimSpace (persona ) == "" {
112+ return "" , fmt .Errorf ("persona required" )
113+ }
96114 dir := resolveAgentsDir ()
97115 agents , err := readAllAgentYAMLs (dir )
98116 if err != nil {
99- c .JSON (http .StatusInternalServerError , gin.H {"error" : fmt .Sprintf ("failed to read agents: %v" , err )})
100- return
117+ return "" , fmt .Errorf ("failed to read agents: %w" , err )
101118 }
102119 var found * yamlAgent
103120 for i := range agents {
@@ -107,8 +124,7 @@ func getAgentMarkdown(c *gin.Context) {
107124 }
108125 }
109126 if found == nil {
110- c .JSON (http .StatusNotFound , gin.H {"error" : "persona not found" })
111- return
127+ return "" , fmt .Errorf ("persona not found" )
112128 }
113129 var sb strings.Builder
114130 fmt .Fprintf (& sb , "# %s (%s)\n \n " , found .Name , found .Persona )
@@ -124,5 +140,5 @@ func getAgentMarkdown(c *gin.Context) {
124140 if found .SystemMessage != "" {
125141 fmt .Fprintf (& sb , "\n ## System message\n \n %s\n " , found .SystemMessage )
126142 }
127- c . Data ( http . StatusOK , "text/markdown; charset=utf-8" , [] byte ( sb .String ()))
143+ return sb .String (), nil
128144}
0 commit comments