Skip to content

mission control for agent skills

fix: address greptile review findings

Alvin Unreal983fb656ee8d
diff --git a/internal/registry/registry.go b/internal/registry/registry.go
index 5d964df..8ae1851 100644
--- a/internal/registry/registry.go
+++ b/internal/registry/registry.go
@@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
+ "io"
"net/http"
"net/url"
"os"
@@ -34,15 +35,29 @@ type Client struct {
// NewClient returns a registry Client initialized with base URL from environment or fallback, and a default timeout.
func NewClient() *Client {
+ c := &Client{}
+ c.BaseURL = c.baseURL()
+ c.HTTPClient = c.httpClient()
+ return c
+}
+
+func (c *Client) baseURL() string {
+ if c.BaseURL != "" {
+ return c.BaseURL
+ }
baseURL := os.Getenv("SKILLS_API_URL")
if baseURL == "" {
baseURL = "https://skills.sh"
}
- return &Client{
- BaseURL: baseURL,
- HTTPClient: &http.Client{
- Timeout: 9 * time.Second,
- },
+ return baseURL
+}
+
+func (c *Client) httpClient() *http.Client {
+ if c.HTTPClient != nil {
+ return c.HTTPClient
+ }
+ return &http.Client{
+ Timeout: 9 * time.Second,
}
}
@@ -62,29 +77,16 @@ func (c *Client) Search(ctx context.Context, query string, limit int) ([]Skill,
return nil, nil
}
- baseURL := c.BaseURL
- if baseURL == "" {
- baseURL = os.Getenv("SKILLS_API_URL")
- if baseURL == "" {
- baseURL = "https://skills.sh"
- }
- }
-
- httpClient := c.HTTPClient
- if httpClient == nil {
- httpClient = &http.Client{
- Timeout: 9 * time.Second,
- }
- }
+ baseURL := c.baseURL()
+ httpClient := c.httpClient()
parsedURL, err := url.Parse(baseURL)
if err != nil {
return nil, fmt.Errorf("invalid base URL %q: %w", baseURL, err)
}
- u := parsedURL.ResolveReference(&url.URL{
- Path: "/api/search",
- })
+ u := *parsedURL
+ u.Path = strings.TrimSuffix(u.Path, "/") + "/api/search"
q := url.Values{}
q.Set("q", query)
if limit > 0 {
@@ -107,8 +109,9 @@ func (c *Client) Search(ctx context.Context, query string, limit int) ([]Skill,
return nil, fmt.Errorf("unexpected registry response status: %d", resp.StatusCode)
}
+ limitedBody := io.LimitReader(resp.Body, 2*1024*1024)
var res apiResponse
- if err := json.NewDecoder(resp.Body).Decode(&res); err != nil {
+ if err := json.NewDecoder(limitedBody).Decode(&res); err != nil {
return nil, fmt.Errorf("failed to parse registry json response: %w", err)
}
diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go
index 15906b8..2f9ae44 100644
--- a/internal/registry/registry_test.go
+++ b/internal/registry/registry_test.go
@@ -5,6 +5,7 @@ import (
"net/http"
"net/http/httptest"
"net/url"
+ "strings"
"testing"
)
@@ -218,3 +219,49 @@ func TestSearchSanitization(t *testing.T) {
t.Errorf("expected unsafe command fields to mark result invalid, got %+v", s)
}
}
+
+func TestResolveReferencePreservesBasePath(t *testing.T) {
+ calledPath := ""
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ calledPath = r.URL.Path
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"skills": []}`))
+ }))
+ defer server.Close()
+
+ client := &Client{
+ BaseURL: server.URL + "/v2",
+ }
+ _, err := client.Search(context.Background(), "query", 5)
+ if err != nil {
+ t.Fatalf("unexpected error: %v", err)
+ }
+
+ expectedPath := "/v2/api/search"
+ if calledPath != expectedPath {
+ t.Errorf("expected called path to be %q, got %q", expectedPath, calledPath)
+ }
+}
+
+func TestSearchResponseBodyLimit(t *testing.T) {
+ server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
+ w.Header().Set("Content-Type", "application/json")
+ _, _ = w.Write([]byte(`{"skills": [`))
+ largeVal := strings.Repeat(`{"id": "owner/repo/friendly-skill", "name": "friendly-skill", "installs": 10, "source": "owner/repo"},`, 25000)
+ _, _ = w.Write([]byte(largeVal))
+ _, _ = w.Write([]byte(`]}`))
+ }))
+ defer server.Close()
+
+ client := &Client{
+ BaseURL: server.URL,
+ }
+
+ _, err := client.Search(context.Background(), "query", 5)
+ if err == nil {
+ t.Fatal("expected error due to response body size limit, but got nil")
+ }
+ if !strings.Contains(err.Error(), "failed to parse registry json response") {
+ t.Errorf("expected error message to contain 'failed to parse registry json response', got %q", err.Error())
+ }
+}
diff --git a/internal/tui/view.go b/internal/tui/view.go
index 6f37c7a..deb9279 100644
--- a/internal/tui/view.go
+++ b/internal/tui/view.go
@@ -1723,10 +1723,14 @@ func (m appModel) registryModalOverlay(layout appLayout) string {
if !m.registryFocusList {
focusPrompt = "Search › "
}
+ cursor := ""
+ if !m.registryFocusList {
+ cursor = "_"
+ }
if m.registryQuery == "" {
- inputLine = focusPrompt + dimStyle.Render("Type to search...")
+ inputLine = focusPrompt + dimStyle.Render("Type to search...") + cursor
} else {
- inputLine = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Bold(true).Render(focusPrompt) + m.registryQuery + "_"
+ inputLine = lipgloss.NewStyle().Foreground(lipgloss.Color("205")).Bold(true).Render(focusPrompt) + m.registryQuery + cursor
}
var leftContentLines []string
@@ -1926,7 +1930,7 @@ func (m appModel) registryModalHelpLine() string {
}
return "type search · tab select list · esc close"
}
- parts := []string{"type search", "↑/↓ choose"}
+ parts := []string{"↑/↓ choose"}
if m.selectedRegistryResultInstallable() {
parts = append(parts, "enter install to project", "g install globally")
} else {