MCPcopy Create free account
hub / github.com/atripati/ark / autoFixCodeInResponse

Function autoFixCodeInResponse

pkg/runtime/quality.go:562–585  ·  view source on GitHub ↗
(response string)

Source from the content-addressed store, hash-verified

560}
561
562func autoFixCodeInResponse(response string) string {
563 re := regexp.MustCompile("(?s)(```(?:go)?\\s*\n)(.*?)(```)")
564 return re.ReplaceAllStringFunc(response, func(match string) string {
565 parts := re.FindStringSubmatch(match)
566 if len(parts) != 4 {
567 return match
568 }
569 opener := parts[1] // ```go\n
570 code := parts[2] // the code content
571 closer := parts[3] // ```
572
573 // Detect language — only fix Go code
574 lang := strings.TrimSpace(strings.TrimPrefix(strings.TrimSpace(opener), "```"))
575 if lang == "" {
576 lang = detectCodeLanguageFromContent(code)
577 }
578
579 if lang == "go" || lang == "" {
580 fixed := AutoFixGoCode(code)
581 return opener + fixed + closer
582 }
583 return match
584 })
585}
586
587// detectCodeLanguageFromContent guesses language from code content.
588func detectCodeLanguageFromContent(code string) string {

Callers 1

RunMethod · 0.85

Calls 2

AutoFixGoCodeFunction · 0.85

Tested by

no test coverage detected