Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pig.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: go test ./...

- name: Install PiG
run: go install github.com/MichaelKinsy/PiG/cmd/pig@v0.5.2
run: go install github.com/MichaelKinsy/PiG/cmd/pig@v0.9.0

- name: Validate package
run: pig package validate ./pig --json
Expand Down
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
- `pig/` holds the Go port for PiG (the Go reimplementation of Pi): the factory extension in `pig/extensions/litellm`,
a mock LiteLLM proxy in `pig/tools/mockproxy`, the PiG package manifest and an example fused Piglet. Read
`pig/PORTING.md` before touching it; it records the design decisions, the port map, the conventions and the PiG
0.5.2 issues that remain (the empty thinking-level crash, the SDK pin PiG ignores, a silent build failure).
0.9.0 issues that remain (the empty thinking-level crash, the SDK pin PiG ignores, a silent build failure).
`pig/README.md` is the user-facing documentation.
- The Go module depends on `github.com/MichaelKinsy/PiG` and its `extensions/sdk` at the same version as the `pig`
binary in use; bump both together.
Expand Down
17 changes: 9 additions & 8 deletions pig/PORTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pig/
├── PORTING.md this brief
├── package.json PiG package manifest (phase 6)
└── extensions/litellm/ Go module github.com/balcsida/pi-provider-litellm/pig/extensions/litellm
├── go.mod requires github.com/MichaelKinsy/PiG v0.5.2 and .../extensions/sdk v0.5.2
├── go.mod requires github.com/MichaelKinsy/PiG v0.9.0 and .../extensions/sdk v0.9.0
├── extension.go factory: func Extension() *sdk.Extension ← src/index.ts
├── provider.go LiteLLM native provider ← src/provider.ts
├── models_store.go stored-catalog seed ← src/models-store.ts
Expand Down Expand Up @@ -105,7 +105,7 @@ are taken from it: the native `providers.litellm` slot and `litellm.providers.<n
## Verification ladder

1. `go test ./...` in `pig/extensions/litellm`.
2. `pig install --validate-only --json ./pig/extensions/litellm` proves the factory builds and registers: PiG 0.5.2
2. `pig install --validate-only --json ./pig/extensions/litellm` proves the factory builds and registers: PiG 0.9.0
reports `"valid": true` and `"registered": true`. `pig package validate ./pig --json` validates the Go member
too.
3. Live smoke against the mock proxy in `pig/tools/mockproxy` (`go run . -key test-key -addr 127.0.0.1:48417`):
Expand Down Expand Up @@ -140,7 +140,7 @@ are taken from it: the native `providers.litellm` slot and `litellm.providers.<n
```

`LOGIN_SMOKE_MODE` is `cli`, `pkce`, `paste` or `apikey`; the mock's `-sso` mode must match the first three.
Stock PiG 0.5.2 passes this step in all four modes. On a desktop PiG also opens the authorize URL in the browser;
Stock PiG 0.9.0 passes this step in all four modes. On a desktop PiG also opens the authorize URL in the browser;
when the browser's callback lands first, the `pkce` driver's own fetch fails with `ECONNREFUSED`, so run it again.

## Status
Expand All @@ -159,7 +159,7 @@ Intentional differences from the TypeScript extension, all forced by PiG:
stored record as the restore failure, because Go's `EnrichCachedModel` cannot fail where the TypeScript one throws.
The typed store now rejects a malformed record on the host side before the extension sees it, so only
extension-only fields (`litellmPolicy` and the like) can still fail there.
- PiG 0.5.2 emits `model_select` from `coding/session.go`, with `data["model"]`, `data["previousModel"]` and
- PiG 0.9.0 emits `model_select` from `coding/session.go`, with `data["model"]`, `data["previousModel"]` and
`data["source"]`. The budget status line follows the provider in `data["model"]["provider"]`;
`before_agent_start`, `turn_end` and `session_start` remain as a fallback through `ctx.ModelProvider()` for a host
that does not emit it.
Expand Down Expand Up @@ -187,17 +187,18 @@ Intentional differences from the TypeScript extension, all forced by PiG:
`/v1/systemone`, the bridge maps neither `Classify` nor `GetAllModels`, and the Go discovery keeps withholding those
groups like any other non-chat mode.

## Known PiG 0.5.2 issues
## Known PiG issues (re-verified on 0.9.0)

- A reasoning model whose `thinkingLevelMap` denies every level (the TypeScript's `NO_TRANSMISSIBLE_LEVELS`, emitted
when no effort carrier is evidenced, for example a Claude route on Chat Completions without
`reasoning_effort_levels`) crashes PiG at model selection: `coding/model.go:175` (`thinkingMaxLevelForEntry`) indexes
`reasoning_effort_levels`) crashes PiG at model selection: `coding/model.go:252` (`thinkingMaxLevelForEntry`) indexes
the last element of the empty list `ai.GetSupportedThinkingLevels` returns. Pi tolerates the same model. The fix
belongs in PiG (return `""` when the list is empty); the extension deliberately keeps the TypeScript semantics rather
than inventing a level.
than inventing a level. Still unfixed in 0.9.0, where the guard is still absent (it was `coding/model.go:175` in
0.5.2). Denying only `off`, as the `thinking_always_on` evidence does, cannot empty the list on its own.
- PiG 0.5.x compiles a Go extension against the host's own SDK and ignores the `go.mod` SDK pin of the extension.
SDK 0.5.2's `ModelRegistry.Find` also returns an error, so this extension needs PiG 0.5.2 or later; a 0.5.1 host
cannot load it.
cannot load it. Not re-verified on 0.9.0, which is now the pinned floor.
- When the extension fails to build, `--list-models` exits 0 and prints only `No models available`, while `-p` and
`pig install --validate-only --json` report the build error.
- Fixed in 0.5.1: `/login litellm` offers the login flows under their `loginLabel`, answers `select` prompts and runs
Expand Down
22 changes: 9 additions & 13 deletions pig/extensions/litellm/go.mod
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
module github.com/balcsida/pi-provider-litellm/pig/extensions/litellm

go 1.26.0
go 1.27.0

require (
github.com/MichaelKinsy/PiG v0.5.2
github.com/MichaelKinsy/PiG/extensions/sdk v0.5.2
github.com/MichaelKinsy/PiG v0.9.0
github.com/MichaelKinsy/PiG/extensions/sdk v0.9.0
)

require (
cloud.google.com/go/compute/metadata v0.9.0 // indirect
github.com/aws/aws-sdk-go-v2 v1.47.1 // indirect
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 // indirect
github.com/aws/aws-sdk-go-v2/credentials v1.19.16 // indirect
github.com/aws/aws-sdk-go-v2/feature/ec2/imds v1.18.23 // indirect
github.com/aws/smithy-go v1.28.1 // indirect
github.com/dlclark/regexp2 v1.12.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/gorilla/websocket v1.5.3 // indirect
github.com/klauspost/compress v1.19.2 // indirect
golang.org/x/net v0.60.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20240701034025-d67f41855da4 // indirect
github.com/klauspost/compress v1.20.3 // indirect
golang.org/x/net v0.62.0 // indirect
golang.org/x/oauth2 v0.37.0 // indirect
golang.org/x/sys v0.48.0 // indirect
golang.org/x/text v0.42.0 // indirect
golang.org/x/sys v0.49.0 // indirect
golang.org/x/text v0.43.0 // indirect
)
52 changes: 26 additions & 26 deletions pig/extensions/litellm/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdB
cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10=
github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk=
github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho=
github.com/MichaelKinsy/PiG v0.5.2 h1:RJpz3DqE8Cj+7rZKyRZQel76DOPFYnqPhmJougayJfI=
github.com/MichaelKinsy/PiG v0.5.2/go.mod h1:3pE6fQQ7x6NBb8lZKcpLZTi0DL0IkD7wI33NR9sXSa0=
github.com/MichaelKinsy/PiG/extensions/sdk v0.5.2 h1:V6R50PNK6nu/icwHRMYCeeIwkJedAMFCIDcgCyhb5R0=
github.com/MichaelKinsy/PiG/extensions/sdk v0.5.2/go.mod h1:4j0XhCW0EPOBWvqYE7XKjTvIAahI7K1VyyW3KpjTKj8=
github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY=
github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU=
github.com/MichaelKinsy/PiG v0.9.0 h1:WUg8gMNFtAGWSHf/RLKVkD/pR2RmeR/wpUbLWdJdB+I=
github.com/MichaelKinsy/PiG v0.9.0/go.mod h1:bFRS5JmQbfT+E1QlUTwYvNfzqIn7Zdqu1nQscz7qLgs=
github.com/MichaelKinsy/PiG/extensions/sdk v0.9.0 h1:er2DGR+cG5wzLt4jeLPtj7RuAo91WHr01zeWkzFbHg8=
github.com/MichaelKinsy/PiG/extensions/sdk v0.9.0/go.mod h1:4j0XhCW0EPOBWvqYE7XKjTvIAahI7K1VyyW3KpjTKj8=
github.com/Microsoft/go-winio v0.6.4 h1:kJF2pamtYCWXf0xAT8sAkwKC0pMl2HYBrRPHAqyUc+g=
github.com/Microsoft/go-winio v0.6.4/go.mod h1:1xl5JXG4ze/m74GH6Dc4Mwxfc3VL5siRVQjIAlHH07U=
github.com/aws/aws-sdk-go-v2 v1.47.1 h1:uOIZnp4PK3ZhKI0dNrJrhTEsLxbpXHTAJlwoS1pvAtw=
github.com/aws/aws-sdk-go-v2 v1.47.1/go.mod h1:bttEH6JqnUL8LepvDVfdrds/fZ5bCIxzpe3abyUrhDU=
github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.10 h1:gx1AwW1Iyk9Z9dD9F4akX5gnN3QZwUB20GGKH/I+Rho=
Expand All @@ -34,31 +34,31 @@ github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aNNg=
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/gorilla/websocket v1.5.4-0.20240701034025-d67f41855da4 h1:PYKzliEgITjLJoJqbV90S0YRaG8LNAsICH6fp6MApC0=
github.com/gorilla/websocket v1.5.4-0.20240701034025-d67f41855da4/go.mod h1:r4w70xmWCQKmi1ONH4KIaBptdivuRPyosB9RmPlGEwA=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8=
github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ=
github.com/klauspost/compress v1.20.3 h1:zWNoFqq/lSuYQRim3dUXlXeA0IqwuZGicdG5ZTfY5j4=
github.com/klauspost/compress v1.20.3/go.mod h1:LUdAzn7YLVvxLpc7y3V1m40wESHTgc1422pwwBSKYuI=
github.com/lucasb-eyer/go-colorful v1.4.0 h1:UtrWVfLdarDgc44HcS7pYloGHJUjHV/4FwW4TvVgFr4=
github.com/lucasb-eyer/go-colorful v1.4.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-runewidth v0.0.23 h1:7ykA0T0jkPpzSvMS5i9uoNn2Xy3R383f9HDx3RybWcw=
github.com/mattn/go-runewidth v0.0.23/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs=
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa h1:QSyA8ishJCyT21kER9KwNt0b7BM3iRK4x9QXhjN5Fdk=
golang.org/x/exp v0.0.0-20260824195058-e88cd73687aa/go.mod h1:zeBbvyFKDaLwa7CH/zI8KXt7gTl14SF7sO08Pl5jBCM=
golang.org/x/image v0.45.0 h1:FMb1nTbH5H9vF55SriQHgFw5GnNL9Jg6L25BwXKzhB0=
golang.org/x/image v0.45.0/go.mod h1:n62x/7RqlwXDvGsSU4u6IUTUf6KghUZ9Bt7cG/T9Fx4=
golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c=
golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o=
golang.org/x/net v0.60.0 h1:79p50tfZlm0J9YfoDsSi639qSXNGVwEzOPLCxM2FsYU=
golang.org/x/net v0.60.0/go.mod h1:2DA/G1UfVbCpQPeWTmMPGY7Cs2PkBkwu743bVX5PIVg=
github.com/tetratelabs/wazero v1.12.0 h1:DuWcpNu/FzgEXgGBDp8J1Spc+CWOvvtvVyjKlaZopYU=
github.com/tetratelabs/wazero v1.12.0/go.mod h1:LvKtzl2RqO4gyF27BiXU+nKAjcV8f38U+kP/q2vgxh0=
go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw=
go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg=
golang.org/x/exp v0.0.0-20261106112924-d498a4c2cc9a h1:9UV0zqnJ1V2Wl9FOg3EVZ28FPXBPshV27cHJeoE8RTg=
golang.org/x/exp v0.0.0-20261106112924-d498a4c2cc9a/go.mod h1:EJDHCytiW+krTUcAo0SrNw+S0Ukgipv/AnFvgpvOAvc=
golang.org/x/mod v0.42.0 h1:ICeL3t2L30ljSPHHxDnR4fqVcBt/zR2zJAb9juavmQg=
golang.org/x/mod v0.42.0/go.mod h1:u5fzIrRInkL8MaO1cbRkUHT64v303YIT5KEqpNr7jRs=
golang.org/x/net v0.62.0 h1:18ELalfM5+XNRwzM2nYqXsZQ9ByS1uhj2O/U7+5jqRY=
golang.org/x/net v0.62.0/go.mod h1:WgDCOTH8iwtB66T4/GfI94AHo/hhdb7Hah9NDseQfiI=
golang.org/x/oauth2 v0.37.0 h1:JUlcxA8oAtauLfiH8FX2/FkAWHAdi0QtGCGc+hofE98=
golang.org/x/oauth2 v0.37.0/go.mod h1:IxwZNxUULJmpBFf9K/9NTMSIfZZuvuTy1gGxhigP/58=
golang.org/x/sys v0.48.0 h1:bbX/i/6MgT9BVLM9RT1thmxL04yeTAhbEz4SyadbXoo=
golang.org/x/sys v0.48.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.46.0 h1:3+OXuTbaKDgwk8jTi3aSLHRlmWqHEUDUtxnbFigO4YE=
golang.org/x/term v0.46.0/go.mod h1:+K02xbkittuwc0Am4abfA3Fc+XRGXkvBXNO88NCXPoc=
golang.org/x/text v0.42.0 h1:JbOZXgfeCPU9gacVtYliJqOhD+zhrEqK4LfdpmlUZqI=
golang.org/x/text v0.42.0/go.mod h1:ojzP1Z+2QtioaF8DTtO8K5q7JWVVYwZKenzujK0Zd0E=
golang.org/x/sys v0.49.0 h1:XbzkgYJHdqh/8m2Uu0W/dQv8nktxx4BFHp1M0gROTXA=
golang.org/x/sys v0.49.0/go.mod h1:hNLxWAXmnKAxqDtdwIYC4bM9oQPEecfsnNMuSxOs3og=
golang.org/x/term v0.47.0 h1:cpyOwQkr2Nzxe2p6KnrTG7Ei2wtzjsuSjhpXXepZ/BM=
golang.org/x/term v0.47.0/go.mod h1:efAfAuG6RKABvg1ArGebRkvX6LXul14SM67o2e4mUCY=
golang.org/x/text v0.43.0 h1:1QivrlhwAsnMOcqgOdl9my7s9OyZl8O5/UGUTJVXoWc=
golang.org/x/text v0.43.0/go.mod h1:hbSIYA/amXcRXTFSZqh8tWHEoqRvvbKPJ2uz/KU+a+s=
4 changes: 2 additions & 2 deletions pig/extensions/litellm/internal/catalog/catalog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,8 @@ func withoutAzureCatalog(t *testing.T) {

func TestLoadPublicCatalog_FallsBackToOpenAIWhenAzureDoesNotKnowModel(t *testing.T) {
withoutAzureCatalog(t)
r := mustLookup(t, loadFresh(t, map[string]any{}), "azure", "gpt-4")
if r.Source != "pi-vendor" || r.Provider != "openai" || *r.Limits.Context != 8192 {
r := mustLookup(t, loadFresh(t, map[string]any{}), "azure", "gpt-4o")
if r.Source != "pi-vendor" || r.Provider != "openai" || *r.Limits.Context != 128000 {
t.Fatalf("record = %+v limits %+v", r, r.Limits)
}
}
Expand Down
25 changes: 23 additions & 2 deletions pig/extensions/litellm/proxy_protocol_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,19 @@ func TestAzureResponsesAPIOnALiteLLMModel(t *testing.T) {
})
}

// managedEffort returns the effort of the last mid-conversation output_config marker in a managed-effort
// request body, which is the level actually in force for the turn (PiG divergence D130).
func managedEffort(body map[string]any) any {
messages, _ := body["messages"].([]any)
for i := len(messages) - 1; i >= 0; i-- {
message, _ := messages[i].(map[string]any)
if marker, ok := message["output_config"].(map[string]any); ok {
return marker["effort"]
}
}
return nil
}

func TestManagedEffortFollowsClaudeRouting(t *testing.T) {
// LiteLLM reports the cost-map provider of base_model, so the hosted deployment still reads as `anthropic`.
direct := `{"model_name":"team-claude","litellm_params":{"model":"anthropic/claude-opus-5-5","custom_llm_provider":"anthropic"},` +
Expand Down Expand Up @@ -260,8 +273,16 @@ func TestManagedEffortFollowsClaudeRouting(t *testing.T) {
thinking, _ := requests[0].body["thinking"].(map[string]any)
outputConfig, _ := requests[0].body["output_config"].(map[string]any)
_, binding := thinking["block_binding"]
if thinking["type"] != "adaptive" || outputConfig["effort"] != "high" || binding != tc.wantBinding {
t.Fatalf("thinking = %v output_config = %v", thinking, outputConfig)
// PiG 0.9.0 (divergence D130) sends each managed-effort field only with its own beta: the selected
// level rides in a trailing mid-conversation output_config marker under
// mid-conversation-output-config-2026-07-01, and the top-level output_config keeps the baseline.
// Read the effective effort where the opt-in puts it, or the assertion reads the floor instead.
effort := outputConfig["effort"]
if tc.optIn {
effort = managedEffort(requests[0].body)
}
if thinking["type"] != "adaptive" || effort != "high" || binding != tc.wantBinding {
t.Fatalf("thinking = %v output_config = %v effort = %v", thinking, outputConfig, effort)
}
for _, beta := range bindingBetas {
if got := strings.Contains(requests[0].header.Get("anthropic-beta"), beta); got != tc.wantBinding {
Expand Down