Skip to content

Shared task board where people and AI coding agents work as teammates. Source-available, self-hostable.

Go

fix: parse pi --list-models table format for model discovery (#2281)

Leonardo Diego8d5a6138fe57
diff --git a/server/pkg/agent/models.go b/server/pkg/agent/models.go
index b66e2a1b0a..b6a120a64c 100644
--- a/server/pkg/agent/models.go
+++ b/server/pkg/agent/models.go
@@ -299,9 +299,6 @@ func discoverPiModels(ctx context.Context, executablePath string) ([]Model, erro
return parsePiModels(text), nil
}
-// parsePiModels accepts the `pi --list-models` output and extracts
-// model IDs. Pi's format uses `provider:model` rows; we normalize to
-// the same `provider/model` form as opencode for UI consistency.
func parsePiModels(output string) []Model {
scanner := bufio.NewScanner(strings.NewReader(output))
scanner.Buffer(make([]byte, 0, 64*1024), 1024*1024)
@@ -312,15 +309,22 @@ func parsePiModels(output string) []Model {
if line == "" {
continue
}
- first := strings.Fields(line)
- if len(first) == 0 {
+ fields := strings.Fields(line)
+ if len(fields) == 0 {
continue
}
- id := first[0]
- if !strings.ContainsAny(id, ":/") {
+ first := fields[0]
+ if strings.EqualFold(first, "provider") {
+ continue
+ }
+ var id string
+ if strings.ContainsAny(first, ":/") {
+ id = first
+ } else if len(fields) >= 2 {
+ id = first + "/" + fields[1]
+ } else {
continue
}
- // Normalize ":" to "/" since pi uses colon but opencode/UI uses slash.
id = strings.Replace(id, ":", "/", 1)
if seen[id] {
continue
diff --git a/server/pkg/agent/models_test.go b/server/pkg/agent/models_test.go
index fce4311f24..5ad2b82e1f 100644
--- a/server/pkg/agent/models_test.go
+++ b/server/pkg/agent/models_test.go
@@ -197,6 +197,29 @@ bareword
}
}
+func TestParsePiModelsTableFormat(t *testing.T) {
+ input := `provider model context max-out thinking images
+bailian-coding-plan glm-4.7 202.8K 16.4K no no
+bailian-coding-plan qwen3.6-plus 1M 65.5K no yes
+opencode claude-sonnet-4-6 1M 64K yes yes
+opencode claude-sonnet-4-6 1M 64K yes yes
+bareword-only-line
+`
+ models := parsePiModels(input)
+ if len(models) != 3 {
+ t.Fatalf("expected 3 models (header skipped, duplicate deduped, bareword skipped), got %d: %+v", len(models), models)
+ }
+ if models[0].ID != "bailian-coding-plan/glm-4.7" || models[0].Provider != "bailian-coding-plan" {
+ t.Errorf("unexpected first model: %+v", models[0])
+ }
+ if models[1].ID != "bailian-coding-plan/qwen3.6-plus" || models[1].Provider != "bailian-coding-plan" {
+ t.Errorf("unexpected second model: %+v", models[1])
+ }
+ if models[2].ID != "opencode/claude-sonnet-4-6" || models[2].Provider != "opencode" {
+ t.Errorf("unexpected third model: %+v", models[2])
+ }
+}
+
func TestParseOpenclawAgents(t *testing.T) {
input := `deepseek-v4 deepseek-v4
claude-sonnet claude-sonnet-4-6