Skip to content

Commit 34b0e70

Browse files
barckcodeclaude
andcommitted
Fix: Improve output formatting and release instructions
- Fix output formatting by sanitizing markdown code fences - Improve text wrapping and display in formatter - Add regex-based markdown cleanup in parser - Enhance release instructions with better installation guide - Prepare for v0.1.1 patch release 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent ce08fce commit 34b0e70

3 files changed

Lines changed: 35 additions & 11 deletions

File tree

.github/workflows/releases.yml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,17 @@ jobs:
3434
3535
**macOS/Linux:**
3636
```bash
37-
# Download the binary for your platform
38-
curl -LO https://github.com/${{ github.repository }}/releases/download/${{ github.ref_name }}/kubectl-ai-$(uname -s | tr '[:upper:]' '[:lower:]')-$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/')
37+
# Detect platform
38+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
39+
ARCH=$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/;s/arm64/arm64/')
3940
40-
# Make it executable
41-
chmod +x kubectl-ai-*
41+
# Download and extract the tarball
42+
curl -LO "https://github.com/helmcode/kubectl-ai/releases/download/${{ github.ref_name }}/kubectl-ai-${OS}-${ARCH}.tar.gz"
43+
tar -xzf kubectl-ai-${OS}-${ARCH}.tar.gz
4244
43-
# Move to your PATH
44-
sudo mv kubectl-ai-* /usr/local/bin/kubectl-ai
45+
# Make it executable and move to your PATH
46+
chmod +x kubectl-ai-${OS}-${ARCH}
47+
sudo mv kubectl-ai-${OS}-${ARCH} /usr/local/bin/kubectl-ai
4548
```
4649
4750
**Windows:**

pkg/formatter/output.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package formatter
33
import (
44
"encoding/json"
55
"fmt"
6+
"regexp"
67
"strings"
78

89
"github.com/fatih/color"
@@ -88,15 +89,15 @@ func displayHuman(analysis *model.Analysis) {
8889
}
8990

9091
if suggestion.Explanation != "" {
91-
fmt.Printf(" Why: %s\n", suggestion.Explanation)
92+
fmt.Println(wrapText("Why: "+sanitizeText(suggestion.Explanation), 80, " "))
9293
}
9394
fmt.Println()
9495
}
9596
}
9697

9798
if analysis.FullAnalysis != "" {
9899
white.Println("📄 DETAILED ANALYSIS:")
99-
fmt.Println(wrapText(analysis.FullAnalysis, 80, " "))
100+
fmt.Println(wrapText(sanitizeText(analysis.FullAnalysis), 80, " "))
100101
fmt.Println()
101102
}
102103
fmt.Println(strings.Repeat("─", 80))
@@ -146,6 +147,13 @@ func getPriorityIcon(priority string) string {
146147
}
147148
}
148149

150+
// sanitizeText removes markdown code fences to keep output clean
151+
func sanitizeText(text string) string {
152+
// Remove ```json, ```yaml, ``` and matching closing fences
153+
re := regexp.MustCompile("```[a-zA-Z]*\n|```")
154+
return re.ReplaceAllString(text, "")
155+
}
156+
149157
func wrapText(text string, width int, indent string) string {
150158
var result strings.Builder
151159
lines := strings.Split(text, "\n")

pkg/parser/debug.go

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,19 @@
11
package parser
22

3-
import "encoding/json"
3+
import (
4+
"encoding/json"
5+
"regexp"
6+
"strings"
7+
)
48

59
import "github.com/helmcode/kubectl-ai/pkg/model"
610

711
func ParseDebugResponse(raw string, problem string) (*model.Analysis, error) {
12+
// Remove markdown code fences if present
13+
cleaned := stripFences(raw)
14+
815
var analysis model.Analysis
9-
if err := json.Unmarshal([]byte(raw), &analysis); err != nil {
16+
if err := json.Unmarshal([]byte(cleaned), &analysis); err != nil {
1017
// Fallback – could not parse JSON, embed entire text.
1118
analysis = model.Analysis{
1219
Problem: problem,
@@ -28,5 +35,11 @@ func ParseDebugResponse(raw string, problem string) (*model.Analysis, error) {
2835
if analysis.Problem == "" {
2936
analysis.Problem = problem
3037
}
31-
return &analysis, nil
38+
return &analysis, nil
39+
}
40+
41+
// stripFences removes markdown code fences such as ```json ... ``` so JSON can be parsed
42+
func stripFences(text string) string {
43+
re := regexp.MustCompile("```[a-zA-Z]*\n|```")
44+
return strings.TrimSpace(re.ReplaceAllString(text, ""))
3245
}

0 commit comments

Comments
 (0)