Skip to content

Commit b15c546

Browse files
kevinelliottclaude
andcommitted
Fix linting issues and improve JSON output
Code Quality Fixes: - Fixed prealloc warnings by pre-allocating slices with capacity - Fixed gofmt formatting issues across multiple files - Fixed errcheck issues by explicitly handling or ignoring errors - Reduced cyclomatic complexity in getScriptVersion by extracting helper functions JSON Output Improvements: - Skip AgentPipe logo/banner when --json flag is used - Ensures clean JSON-only output for programmatic usage - Applies to all commands with --json flag All tests pass with race detector. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 41d1666 commit b15c546

File tree

4 files changed

+90
-52
lines changed

4 files changed

+90
-52
lines changed

cmd/agents.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ import (
1414
)
1515

1616
var (
17-
installAll bool
18-
listInstalled bool
19-
listOutdated bool
20-
listCurrent bool
21-
listJSON bool
17+
installAll bool
18+
listInstalled bool
19+
listOutdated bool
20+
listCurrent bool
21+
listJSON bool
2222
)
2323

2424
// agentsCmd represents the agents command
@@ -32,7 +32,7 @@ Examples:
3232
agentpipe agents install claude # Install Claude CLI
3333
agentpipe agents install --all # Install all agents`,
3434
Run: func(cmd *cobra.Command, args []string) {
35-
cmd.Help()
35+
_ = cmd.Help()
3636
},
3737
}
3838

@@ -122,7 +122,7 @@ func runAgentsList(cmd *cobra.Command, args []string) {
122122
showVersionInfo := listCurrent
123123

124124
// Filter agents based on flags
125-
var filteredAgents []*registry.AgentDefinition
125+
filteredAgents := make([]*registry.AgentDefinition, 0, len(agents))
126126
for _, agent := range agents {
127127
installed := isAgentInstalled(agent.Command)
128128

@@ -556,7 +556,7 @@ func runAgentsUpgrade(cmd *cobra.Command, args []string) {
556556

557557
// outputAgentsJSON outputs agent list in JSON format
558558
func outputAgentsJSON(agents []*registry.AgentDefinition, showVersionInfo bool) {
559-
var jsonAgents []AgentListJSON
559+
jsonAgents := make([]AgentListJSON, 0, len(agents))
560560

561561
for _, agent := range agents {
562562
installed := isAgentInstalled(agent.Command)
@@ -625,15 +625,15 @@ func outputAgentsJSON(agents []*registry.AgentDefinition, showVersionInfo bool)
625625
// outputOutdatedJSON outputs agent version information in JSON format
626626
func outputOutdatedJSON(rows []agentVersionRow) {
627627
type OutdatedAgentJSON struct {
628-
Name string `json:"name"`
629-
Installed bool `json:"installed"`
630-
CurrentVer string `json:"current_version"`
631-
LatestVer string `json:"latest_version"`
632-
HasUpdate bool `json:"has_update"`
633-
CanCheckVer bool `json:"can_check_version"`
628+
Name string `json:"name"`
629+
Installed bool `json:"installed"`
630+
CurrentVer string `json:"current_version"`
631+
LatestVer string `json:"latest_version"`
632+
HasUpdate bool `json:"has_update"`
633+
CanCheckVer bool `json:"can_check_version"`
634634
}
635635

636-
var jsonAgents []OutdatedAgentJSON
636+
jsonAgents := make([]OutdatedAgentJSON, 0, len(rows))
637637
for _, r := range rows {
638638
jsonAgents = append(jsonAgents, OutdatedAgentJSON{
639639
Name: r.name,

cmd/root.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,11 @@ Claude, Gemini, and Qwen, allowing them to communicate in a shared "room".`,
4040
}
4141

4242
func Execute() {
43-
// Skip logo for doctor --json command for clean JSON output
43+
// Skip logo for --json commands for clean JSON output
4444
shouldSkipLogo := false
45-
if len(os.Args) >= 2 && os.Args[1] == "doctor" {
46-
for _, arg := range os.Args[2:] {
45+
if len(os.Args) >= 2 {
46+
// Check if --json flag is present anywhere in args
47+
for _, arg := range os.Args[1:] {
4748
if arg == "--json" {
4849
shouldSkipLogo = true
4950
break

internal/registry/registry_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,12 +139,12 @@ func TestGetUpgradeCommand(t *testing.T) {
139139

140140
func TestIsInstallable(t *testing.T) {
141141
tests := []struct {
142-
name string
143-
wantInstall bool
142+
name string
143+
wantInstall bool
144144
}{
145-
{"Claude", true}, // npm install
146-
{"Ollama", true}, // brew install (darwin) or curl script
147-
{"Amp", true}, // npm install
145+
{"Claude", true}, // npm install
146+
{"Ollama", true}, // brew install (darwin) or curl script
147+
{"Amp", true}, // npm install
148148
}
149149

150150
for _, tt := range tests {

internal/registry/version.go

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,20 @@ func getGitHubLatestRelease(repoName string) (string, error) {
168168

169169
// getScriptVersion fetches version from a shell script that contains VER= definition
170170
func getScriptVersion(scriptURL string) (string, error) {
171+
scriptContent, err := fetchScriptContent(scriptURL)
172+
if err != nil {
173+
return "", err
174+
}
175+
176+
version, err := extractVersionFromScript(scriptContent)
177+
if err != nil {
178+
return "", err
179+
}
180+
181+
return version, nil
182+
}
183+
184+
func fetchScriptContent(scriptURL string) (string, error) {
171185
client := &http.Client{
172186
Timeout: 10 * time.Second,
173187
}
@@ -187,46 +201,69 @@ func getScriptVersion(scriptURL string) (string, error) {
187201
return "", fmt.Errorf("failed to read script: %w", err)
188202
}
189203

190-
// Look for VER="x.y.z" or DOWNLOAD_URL patterns in the script
191-
scriptContent := string(body)
204+
return string(body), nil
205+
}
206+
207+
func extractVersionFromScript(scriptContent string) (string, error) {
192208
lines := strings.Split(scriptContent, "\n")
193209
for _, line := range lines {
194210
line = strings.TrimSpace(line)
195211

196212
// Check for VER="x.y.z" pattern
197-
if strings.HasPrefix(line, "VER=") {
198-
version := strings.TrimPrefix(line, "VER=")
199-
version = strings.Trim(version, "\"'")
200-
if version != "" {
201-
return version, nil
202-
}
213+
if version := extractVERPattern(line); version != "" {
214+
return version, nil
203215
}
204216

205-
// Check for DOWNLOAD_URL with version in path (e.g., /2025.10.17-e060db4/)
206-
if strings.HasPrefix(line, "DOWNLOAD_URL=") {
207-
url := strings.TrimPrefix(line, "DOWNLOAD_URL=")
208-
url = strings.Trim(url, "\"'")
209-
210-
// Extract version from URL path like /2025.10.17-e060db4/
211-
// Split by / and look for version-like segments
212-
parts := strings.Split(url, "/")
213-
for _, part := range parts {
214-
// Look for date-based versions (YYYY.MM.DD-hash) or semantic versions
215-
if strings.Contains(part, ".") && (containsDigit(part) || strings.Contains(part, "-")) {
216-
// Skip common non-version parts
217-
if part != "${OS}" && part != "${ARCH}" && part != "darwin" && part != "linux" &&
218-
part != "x64" && part != "arm64" && !strings.HasSuffix(part, ".tar.gz") &&
219-
!strings.HasSuffix(part, ".zip") {
220-
return part, nil
221-
}
222-
}
223-
}
217+
// Check for DOWNLOAD_URL with version in path
218+
if version := extractVersionFromDownloadURL(line); version != "" {
219+
return version, nil
224220
}
225221
}
226222

227223
return "", fmt.Errorf("no VER or DOWNLOAD_URL version found in script")
228224
}
229225

226+
func extractVERPattern(line string) string {
227+
if strings.HasPrefix(line, "VER=") {
228+
version := strings.TrimPrefix(line, "VER=")
229+
version = strings.Trim(version, "\"'")
230+
return version
231+
}
232+
return ""
233+
}
234+
235+
func extractVersionFromDownloadURL(line string) string {
236+
if !strings.HasPrefix(line, "DOWNLOAD_URL=") {
237+
return ""
238+
}
239+
240+
url := strings.TrimPrefix(line, "DOWNLOAD_URL=")
241+
url = strings.Trim(url, "\"'")
242+
243+
parts := strings.Split(url, "/")
244+
for _, part := range parts {
245+
if isVersionLikePart(part) && !isExcludedPart(part) {
246+
return part
247+
}
248+
}
249+
250+
return ""
251+
}
252+
253+
func isVersionLikePart(part string) bool {
254+
return strings.Contains(part, ".") && (containsDigit(part) || strings.Contains(part, "-"))
255+
}
256+
257+
func isExcludedPart(part string) bool {
258+
excludedParts := []string{"${OS}", "${ARCH}", "darwin", "linux", "x64", "arm64"}
259+
for _, excluded := range excludedParts {
260+
if part == excluded {
261+
return true
262+
}
263+
}
264+
return strings.HasSuffix(part, ".tar.gz") || strings.HasSuffix(part, ".zip")
265+
}
266+
230267
// getManifestVersion fetches version from a JSON manifest with "latest" field
231268
func getManifestVersion(manifestURL string) (string, error) {
232269
client := &http.Client{
@@ -395,12 +432,12 @@ func CompareVersions(v1, v2 string) (int, error) {
395432
if i < len(parts1) {
396433
// Extract numeric part only
397434
numStr := extractNumericPrefix(parts1[i])
398-
fmt.Sscanf(numStr, "%d", &p1)
435+
_, _ = fmt.Sscanf(numStr, "%d", &p1)
399436
}
400437

401438
if i < len(parts2) {
402439
numStr := extractNumericPrefix(parts2[i])
403-
fmt.Sscanf(numStr, "%d", &p2)
440+
_, _ = fmt.Sscanf(numStr, "%d", &p2)
404441
}
405442

406443
if p1 < p2 {

0 commit comments

Comments
 (0)