Skip to content

Commit f94d732

Browse files
fix: align CSGClaw launch with latest releases
Use CSGClaw's official latest metadata and write the current config format directly so launch and update checks work with newer CSGClaw versions. Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f0a55f5 commit f94d732

7 files changed

Lines changed: 303 additions & 236 deletions

File tree

internal/apps/manager.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ import (
2828
)
2929

3030
const (
31-
progressModePercent = "percent"
32-
progressModeIndeterminate = "indeterminate"
33-
mirrorBaseURL = "https://git-devops.opencsg.com/opensource/apps/-/raw/main"
34-
repoRawBaseURL = "https://git-devops.opencsg.com/opensource/csghub-lite/-/raw/main"
35-
installTimeout = 20 * time.Minute
36-
latestVersionCacheTTL = 10 * time.Minute
37-
latestVersionTimeout = 3 * time.Second
38-
installerPTYCols = 120
39-
installerPTYRows = 36
31+
progressModePercent = "percent"
32+
progressModeIndeterminate = "indeterminate"
33+
mirrorBaseURL = "https://git-devops.opencsg.com/opensource/apps/-/raw/main"
34+
repoRawBaseURL = "https://git-devops.opencsg.com/opensource/csghub-lite/-/raw/main"
35+
installTimeout = 20 * time.Minute
36+
latestVersionCacheTTL = 10 * time.Minute
37+
latestVersionTimeout = 3 * time.Second
38+
latestVersionResponseLimit = 64 * 1024
39+
installerPTYCols = 120
40+
installerPTYRows = 36
4041
)
4142

4243
var versionTokenPattern = regexp.MustCompile(`(?i)v?\d+(?:\.\d+)+(?:[-+][0-9A-Za-z.-]+)?`)
@@ -237,9 +238,9 @@ func appSpecs() []appSpec {
237238
disabledReason: csgclawDisabledReason(),
238239
versionArgs: []string{"--version"},
239240
latest: &latestVersionSource{
240-
baseURL: "https://api.github.com/repos/OpenCSGs/csgclaw/releases/latest",
241+
baseURL: "https://csgclaw.opencsg.com/releases/latest",
241242
envVar: "CSGHUB_LITE_CSGCLAW_LATEST_URL",
242-
format: "github-release",
243+
format: "version-json",
243244
},
244245
unix: &scriptSource{
245246
mirrorURL: "https://csgclaw.opencsg.com/install.sh",
@@ -513,7 +514,7 @@ func (m *Manager) fetchLatestVersion(ctx context.Context, spec appSpec) (string,
513514
reqCtx, cancel := context.WithTimeout(ctx, latestVersionTimeout)
514515
defer cancel()
515516
req, err := http.NewRequestWithContext(reqCtx, http.MethodGet, baseURL+"/latest", nil)
516-
if spec.latest.format == "github-release" {
517+
if spec.latest.format == "github-release" || spec.latest.format == "version-json" {
517518
req, err = http.NewRequestWithContext(reqCtx, http.MethodGet, baseURL, nil)
518519
}
519520
if err != nil {
@@ -527,7 +528,7 @@ func (m *Manager) fetchLatestVersion(ctx context.Context, spec appSpec) (string,
527528
if resp.StatusCode < http.StatusOK || resp.StatusCode >= http.StatusMultipleChoices {
528529
return "", fmt.Errorf("latest endpoint returned %s", resp.Status)
529530
}
530-
data, err := io.ReadAll(io.LimitReader(resp.Body, 1024))
531+
data, err := io.ReadAll(io.LimitReader(resp.Body, latestVersionResponseLimit))
531532
if err != nil {
532533
return "", err
533534
}
@@ -540,6 +541,15 @@ func (m *Manager) fetchLatestVersion(ctx context.Context, spec appSpec) (string,
540541
}
541542
return strings.TrimSpace(payload.TagName), nil
542543
}
544+
if spec.latest.format == "version-json" {
545+
var payload struct {
546+
Version string `json:"version"`
547+
}
548+
if err := json.Unmarshal(data, &payload); err != nil {
549+
return "", err
550+
}
551+
return strings.TrimSpace(payload.Version), nil
552+
}
543553
return strings.TrimSpace(string(data)), nil
544554
}
545555

internal/apps/manager_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,32 @@ func TestFetchLatestVersionParsesGitHubReleaseTag(t *testing.T) {
299299
}
300300
}
301301

302+
func TestFetchLatestVersionParsesVersionJSON(t *testing.T) {
303+
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
304+
if r.URL.Path != "/releases/latest" {
305+
t.Fatalf("latest path = %q, want /releases/latest", r.URL.Path)
306+
}
307+
w.Header().Set("Content-Type", "application/json")
308+
_, _ = w.Write([]byte(`{"version":"v0.2.8","count":6}`))
309+
}))
310+
defer server.Close()
311+
312+
mgr := NewManager(nil)
313+
latest, err := mgr.fetchLatestVersion(context.Background(), appSpec{
314+
id: "csgclaw",
315+
latest: &latestVersionSource{
316+
baseURL: server.URL + "/releases/latest",
317+
format: "version-json",
318+
},
319+
})
320+
if err != nil {
321+
t.Fatalf("fetchLatestVersion returned error: %v", err)
322+
}
323+
if latest != "v0.2.8" {
324+
t.Fatalf("latest = %q, want v0.2.8", latest)
325+
}
326+
}
327+
302328
func TestNewManagerBackfillsLegacyManagedClaudeInstall(t *testing.T) {
303329
if runtime.GOOS == "windows" {
304330
t.Skip("legacy Claude launcher backfill is covered on Unix-style installs")

0 commit comments

Comments
 (0)