Repository navigation
feat(pi): chain the proxy in front of an existing base URL - #1010
Conversation
When Pi's models.json already sends anthropic or openai to another endpoint (a company gateway), setup now asks one question: chain, replace, or change nothing. It used to refuse. - chain: Pi -> proxy -> the existing endpoint. The proxy gets the old baseUrl as --anthropic-upstream / --openai-upstream. An OpenAI baseUrl must end in /v1. Other URLs that the proxy cannot reproduce are refused. - replace: Pi -> proxy -> the public API. The question warns that this usually breaks the endpoint's auth. - setup --plan prints paired consent_question_* and confirm_command_* lines. setup without --on-conflict still refuses on a conflict. - The install record keeps the upstreams, so configure, update and a new setup start the proxy with them. proxy.yaml names them in a comment. - status prints the routes. Uninstall and the reset command restore the old baseUrl. A gateway set after our route is now what they restore. Approved by the developer (David Amid) in session on 2026-11-10. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 2 of 2 | 1 of 2 | 76051d87d3c4 |
approve |
Verdict: approve
Findings
None. I could not confirm a defect. Details of what I tried are under "What I checked".
Non-blocking
pi-package/extensions/context-guru.ts:81— The dialog title showsexisting_base_urlas raw JSON, for example{"anthropic":"https://gw.example"}. A person reads JSON. Print the provider names and URLs in plain words instead.pi-package/extensions/context-guru.ts:153— The chained-OpenAI guard (install?.upstreams?.openai) has no test. The other request-shaping rule (forChatGPTSignIn) is a pure, tested helper. Extract the guard the same way, or state why not.pi-package/scripts/pi_plugin.py:554— When both providers clash and one URL is not chainable, chain is refused for both. The person cannot chain one and replace the other; replace then applies to both. A coarse choice, and the consent text does disclose it. Worth a README line.- A recorded chain persists while the provider's
baseUrlin models.json holds our URL. If the user later deletes that key, setup asks nothing and the proxy keeps the--anthropic-upstreamflag. Plan mode and/context-guru statusdo show the route. Uninstall is the only way out. Acceptable, but undocumented. pi-package/scripts/pi_plugin.py:506— The chain consent text says the keep-alive pings "use your own quota on each provider". With a chain, the quota spent is the gateway's. The pings are disclosed; only the wording is off.pi-package/README.md(chain section) — "The proxy removes only its ownx-context-guru-*headers,Cookieand hop-by-hop headers." The proxy also stripsAccept-Encodingon the forward path (proxy/proxy.go:92,counttokens.go). Transport necessity; the word "only" is slightly too strong.
What I checked
- The full diff of all six files, and the unchanged code around each change (
pi_plugin.py,models_route.py,context-guru.ts, both test files,README.md). - Path arithmetic of chain mode. Pi appends
/v1/messages(Anthropic) and/responses(OpenAI) to a baseUrl; the proxy appends/v1/messages,/v1/responses,/v1/chat/completionsand/v1/messages/count_tokensto its upstream (proxy/proxy.go:560-591,counttokens.go:14).chain_upstreammakes both sides equal, including the trailing-slash and/v1cases the tests list. The OpenAI/v1rule is the right refusal for a URL the proxy cannot reproduce. - The proxy flags exist and keep their meaning:
--anthropic-upstream/--openai-upstream(cmd/context-guru-proxy/main.go:97-98). With no key configured,setUpstreamAuthonly scrubs our token and the client'sAuthorization/x-api-keypass through (proxy/proxy.go:2702), so a gateway's key arrives. The README header claim matchescopyHeaders(proxy/proxy.go:3116). chain_upstreamrefusals: bad scheme, missing host, whitespace, userinfo, query, fragment, bad port (ValueError is caught), and the self-loop check against the chosen port. A loop through another host name would 404 (the proxy serves/anthropic/..., not/v1/messages), not cycle.- The
models_route.installre-record rule against every prior test scenario: first install, re-run on a new port withours, a key the user changed, an entry we created, and the new "gateway set after our route" case. The old keep-first-record behavior is preserved for URLs that are ours; only a foreign value re-records. Restore semantics stay consistent. - The setup decision flow: plan prints paired questions and no plain one; no choice refuses with a note; abort changes nothing; chain refuses unchainable URLs before any write; replace pops only the clashing providers. The record, proxy config comment, service command,
configure,update, and a newsetupall carry the upstreams, and the tests assert each. - The extension:
conflictPromptoption/answer mapping (KEEP has no answer, so a KEEP or cancelled select changes nothing), the no-UI paths, and the chained-OpenAI skip of the ChatGPT field removal. The skip is correct: before setup Pi sent those fields to that endpoint and it accepted them. - Uninstall and the reset hatch restore the gateway baseUrl (both tested, including the real
reset.shrun). - Tests read in full; the new Python and Node tests match the code they cover, and
pi_test.goruns both suites in CI. I did not run them (live tests not approved). - Repo rules: fail-open and reversibility are untouched (no library or proxy change); no component or data-dependence change, so
docs/data-dependence.mdneeds no row.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | fresh | 1 of 2 | 1 of 2 | 76051d87d3c4 |
blocking |
Verdict: blocking
Findings
-
pi-package/scripts/pi_plugin.py:583 — chain mode promises the cache strategy, but keep-alive pings cannot carry a gateway's custom auth header
- What fails: a user chains a provider to a gateway that needs a header from
models.jsonheaderson every request (a tenant tag likex-corp-tenant, or an Azure-styleapi-keyheader — the PR's own test fixture and live check use exactly this shape). Every keep-alive ping lacks that header, so the gateway answers 401. After 3 failed pings the route breaker trips for one hour, then the cycle repeats. Keep-alive stays silently off. The chain consent question (pi_plugin.py:506-510) still promises "Cache strategy auto sends small keep-alive requests", and nothing tells the user it cannot work. A corporate gateway may also count the failed auth attempts. - Proof: a ping carries only the
PingHeadersallow-list (keepalive/dispatch.go:6-15: Content-Type, Anthropic-Version, Anthropic-Beta, OpenAI-Organization, OpenAI-Project) plus the held credential, andheldAuthholds only the standard auth slots (proxy/credmask.go:78-89,authHeaders= Authorization, x-api-key, x-goog-api-key inproxy/tenancy.go:237).copyHeadersforwards custom headers on real requests (proxy/proxy.go:3116-3128), so requests work and only pings fail. The breaker trips at 3 failures (keepalive/breaker.go:19-28). The default strategy isauto, so pings are on. Fail open holds: requests are not affected. - Fix: smallest fix inside this PR — when a chained provider's entry has
headers, say in the chain consent question (and the README) that keep-alive needs the gateway's auth inapiKey/Authorization, or it stops. Real fix, proxy-side and later: carry the request's non-secret custom headers on pings.
- What fails: a user chains a provider to a gateway that needs a header from
-
pi-package/scripts/pi_plugin.py:384 —
_systemd_quotedoes not escape%, and chain mode is the first user-supplied string on the service command line- What fails: on Linux, systemd expands
%-specifiers inside a quotedExecStartargument. A chainedbaseUrlwhose path contains%followed by a specifier letter (for examplehttps://gw.example/team%b) silently becomes a different upstream:%bturns into the boot ID,%hinto the home directory,%minto the machine ID. The proxy then sends every request of that provider to the wrong URL and returns 502s./context-guru statusprintsroutesfrom the install record, so it still shows the original URL and the divergence stays invisible. macOS is not affected (launchdProgramArgumentsis an array, no expansion). - Proof:
proxy_command(pi_plugin.py:327-332) puts the chain upstream into the command; the systemd branch writesExecStart=with_systemd_quote(pi_plugin.py:400-406), which escapes only\and".chain_upstream(pi_plugin.py:337-362) refuses whitespace, credentials, queries and non-http URLs, but accepts%in the path. Percent-encoded URLs are safe (a hex digit follows%), so this needs a raw%+ letter — rare, but silent when it hits. - Fix: escape
%as%%in_systemd_quote(and$as$$, since systemd also expands$VARthere). Or refuse a%or$inchain_upstream, like the other refusals.
- What fails: on Linux, systemd expands
-
pi-package/extensions/context-guru.ts:153 — the chained-openai skip in
before_provider_requesthas no test- What fails: new behavior, documented in the README ("A chained
openaiprovider is not changed either"), but nothing tests it. A regression here would silently striptemperature,max_output_tokens,prompt_cache_retentionandprompt_cache_optionsfrom requests to a chained gateway — a behavior change for users the PR promised not to touch. - Proof:
tests/context-guru.test.tscovers only the pure helpers (forChatGPTSignIn,conflictPrompt, …); the skip lives inside the plugin closure, where the Node tests cannot reach it. - Fix: export the decision as a pure helper (like
forChatGPTSignIn), for examplekeepsGatewayFields(install), and test it with and withoutupstreams.openai.
- What fails: new behavior, documented in the README ("A chained
Non-blocking
- The proxy drops the request's query string (
doUpstreambuildsup.base + up.pathonly,proxy/proxy.go:2651). The PR names this as an open question and it matches today's behavior forapi.anthropic.com. I agree: no change needed in this PR, but a chained gateway that keys on?beta=truesees a difference from direct Pi traffic. - README says the proxy removes "only its own
x-context-guru-*headers,Cookieand hop-by-hop headers".Accept-Encodingis also dropped (proxy/proxy.go:2662). A doc nit. models_route.installre-records only when the newbaseUrlis a non-None foreign value. A user who deletesbaseUrlbetween setups keeps the old recordedprevious, so uninstall brings back a value the user removed. This is the pre-PR behavior, and the alternative is ambiguous; noting it only.
What I checked
- Read the full diff (6 files) and the surrounding code in all of them, plus
CLAUDE.mdanddocs/design.md. - Verified every proxy-side claim of the PR against the Go code, unchanged by this PR:
--anthropic-upstream/--openai-upstreamexist (cmd/context-guru-proxy/main.go:97-98, present since the first context-guru release, so the 0.4.0 minimum is fine); the proxy sendsupstream + /v1/messagesandupstream + /v1/responsesand/v1/chat/completions(proxy/proxy.go:560-587,doUpstreamat 2646);count_tokensfollows the Anthropic upstream (proxy/counttokens.go:113-122); headers are forwarded except hop-by-hop,x-context-guru-*,Cookie(copyHeaders); with no server key the caller's credential goes upstream untouched (setUpstreamAuth,bearerKey/headerKey). - Traced
chain_upstreamthrough its test cases and edge cases: trailing slashes,//v1, ports,localhostvs127.0.0.1, IPv6, empty port, uppercase scheme, the same-port loop check, and the cross-provider URL case. All sound. - Traced the
models_route.installre-record change through: first chain, chain re-run with a new gateway, gateway set after our route, old-port repoint, replace after chain, deleted key, created entry later filled by the user. Restore puts back the right value in each. The routing record is written beforemodels.json, andearlieris read before the record changes, as before. - Traced
setupin plan and run mode: paired answers,chain_refused,--on-conflictrefusal without a choice,abort, one-provider conflicts, upstreams kept byconfigure/update/re-setup, record andproxy.yamlcontents, systemd and launchd command construction. - Read all 16 new Python tests and 2 new Node tests; they match the code paths they name.
- Checked the extension flow:
conflictPromptoptions and answers, KEEP as the no-answer, print mode, theneeds_decisiondialog as the consent, and the freshinstallread after setup. - Checked the PR body: it names the behavior change at the top, with the old and new behavior, the undo path, and the approval. Data dependence is stated (none new; routing only) and I agree — the record stores a URL, not customer data.
- README: name what is not tested live (a real answer, keep-alive pings, Sign in with ChatGPT), and cite Pi's engines field for 22.19. - Comparison page: the two open-PR rows name #1010 and #1011. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
- The chain question warns when a chained provider sets headers in models.json: a keep-alive ping carries only Authorization / x-api-key, so the endpoint may refuse it and keep-alive may stop. It suggests /context-guru cache-strategy none. The README says the same. - With a chain, the question says the pings spend quota at the endpoint they reach, not "your own quota on each provider". - _systemd_quote writes % as %% and, on an Exec line, $ as $$. systemd expands both inside quotes, so a chained URL with %b or $X changed. - The chained-openai guard is now a pure helper, stripsChatGPTFields, with a test. The dialog title shows conflicts as "provider: url". - README: chain is offered for both providers or neither, a recorded chain stays until uninstall, and the proxy also drops Accept-Encoding. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
|
Round 1 replies. All fixed in Reviewer 1, blocking
Reviewer 1, non-blocking
Reviewer 2, non-blocking
Tests: Python 49 pass, Node 11 pass. |
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 2 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 2 of 2 | 2 of 2 | 91e7e8af8e65 |
approve |
Verdict: approve
Findings
None. I read the new commit in full and checked each fix against the code. I could not confirm a defect.
Earlier findings
- Reviewer 1, finding 1 (pings cannot carry a gateway's custom headers): fixed by disclosure, and I checked the mechanism.
PingHeaderscopies onlyContent-Type,Anthropic-Version,Anthropic-Beta,OpenAI-Organization,OpenAI-Project(keepalive/dispatch.go:5-15), and the breaker trips a route after 3 failures for one hour (keepalive/breaker.go:10-13). So the warning text is accurate: a ping lacks theheadersfrom models.json, the endpoint may refuse it, and keep-alive stops for that provider while requests keep working. The chain question now warns exactly this when a chained provider setsheadersand the strategy spends, and suggests/context-guru cache-strategy none. The README says the same. Deferring the proxy-side fix (carry custom headers on pings) out of this PR is right: it is a proxy change. - Reviewer 1, finding 2 (systemd
%and$expansion): fixed._systemd_quotenow writes%as%%and, on an Exec line,$as$$; the log paths keep$literal and escape%only, which matches systemd (ExecStartexpands specifiers and variables,StandardOutput=expands specifiers only). The warning covers the real failure: a raw%+ specifier letter in a chained URL changed the upstream silently. - Reviewer 1, finding 3 (untested chained-openai skip): fixed.
stripsChatGPTFields(install)is a pure helper used by the handler, with a Node test of four cases, including a chainedanthropiconly (removal still applies) and a chainedopenai(skip). - Reviewer 1, non-blocking (query string dropped, deleted
baseUrlkeeps the oldprevious): rejected by the author, and I accept both reasons. Each matches the behavior before this PR, and the query-string case is named as an open question. - My round-1 notes: all six fixed or documented —
conflictWords()prints plain words,stripsChatGPTFieldsis tested, the README documents the one-answer-for-both rule and the chain-stays-until-uninstall rule, the quota wording names the endpoint, and "only" is gone from the header sentence.
Non-blocking
pi-package/scripts/pi_plugin.py:520— In the replace question, a provider chained by an earlier setup (kept, not replaced) still triggers the chained quota wording and the headers warning for the whole question. The clashing provider's pings meanwhile go to the public API. Mixed wording only; both statements are true for their own provider.
What I checked
- Last review: round 1,
76051d87d3c4d6a7f7347a1b39f6044d9da3ae3e, 2026-11-10T07:38:30Z. - New commits read: 1 —
91e7e8af"fix(pi): chain review round 1 - ping headers, systemd quoting, tests". - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three saved files; the inline list is empty).
- New items since my last review: reviewer 1's round-1 review (3 blocking, 3 non-blocking findings — I checked each fix or rejection as listed above), the author's round-1 reply comment (all claims verified against the diff), and commit
91e7e8af(reviewed below). - The full new diff, and the code around each change:
_systemd_quote: traced the escaping order (\,",%, then$on Exec lines) against the two new tests, including the unit-file test that runsstart_serviceon systemd with a URL containing%band$x. The unit text carries the upstream literally.has_headers+ the consent-question warning: traced it in the chain question (clashing and kept chains), in the replace question (kept chains only), and with--cache-strategy none(no warning, because nothing spends).has_headersreads models.json safely:_loaderrors are caught.- The quota wording: chain questions say the pings spend quota at the endpoint they reach; non-chain questions keep the old text.
conflictWordsandstripsChatGPTFields: read the helpers and their tests, and confirmed the handler now callsstripsChatGPTFieldswith the same meaning as the old inline guard.- README additions: each new sentence matches behavior I traced in round 1 or in this commit.
- I did not run the tests (live tests not approved). The author reports Python 49 and Node 11 passing.
amiddavid
left a comment
There was a problem hiding this comment.
| Reviewer | Kind | Started by | Context | Review | Round | Head | Verdict |
|---|---|---|---|---|---|---|---|
| Reviewer 1 (glm, user of @amiddavid) | GLM rits/zai-org/glm-5-3 via Claude Code 2.1.322 | offload-review skill, @amiddavid's session | resumed | 1 of 2 | 2 of 2 | 91e7e8af8e65 |
approve |
Verdict: approve
Findings
None. All three round-1 findings are fixed. I checked each fix against the code and the tests.
Earlier findings
Mine, round 1:
- Keep-alive pings cannot carry a gateway's custom auth header — fixed by telling the user.
consent_questionnow warns when a chained provider setsheadersand the strategy spends (pi_plugin.py:512-525): a ping carries onlyAuthorization/x-api-key, the endpoint may refuse it, keep-alive may stop, run/context-guru cache-strategy none. The README says the same and that requests are not affected (README.md, "Keep-alive pings and custom headers"). The warning appears only when the strategy sends pings, and only for chained providers that setheaders— I traced both gates. This is the fix my round-1 review proposed as the smallest one inside this PR. Carrying custom headers on pings stays a proxy change, correctly out of scope here. The ping wording also no longer says "your own quota on each provider" when a chain is in the question. _systemd_quotedid not escape%— fixed. It now writes%as%%always, and$as$$on an Exec line only (pi_plugin.py:384-393). Both escapes match systemd's own rules (systemd.unitspecifiers,systemd.servicecommand lines).StandardOutput/StandardErrorkeep$literal, which is right: those settings expand specifiers but not variables. The order of the replaces cannot interact (\,",%,$are distinct characters). Two tests cover the function and the unit filestart_servicewrites, including an upstream with%band$x.- No test for the chained-openai skip — fixed. The guard is now the exported pure helper
stripsChatGPTFields(context-guru.ts:85-87), used by the handler atcontext-guru.ts:172, with a 4-case Node test (no install, no upstreams, anthropic-only chain, openai chain). The semantics match the old inline check.
My non-blocking notes: Accept-Encoding is now in the README sentence; the query-string and deleted-baseUrl notes were left as is, with the reasons ("same as direct traffic today" and "pre-PR behavior"). Both reasons are right.
Reviewer 2's non-blocking items: I checked each fix myself. conflictWords turns the raw JSON into provider: url words and falls back to the raw text on odd input (tested); the README now documents the one-answer-for-both rule, the chain-stays-until-uninstall rule, and the quota wording is chain-aware. All correct.
Non-blocking
pi_plugin.py:521-522— when both chained providers setheaders, the warning reads "Anthropic and OpenAI sets headers". The verb should be "set". Cosmetic.context-guru.ts:76—conflictWordsjoins with", ", so a URL containing a comma makes the list ambiguous to read. Cosmetic.
What I checked
- Last review: round 1, 76051d8, 2026-11-10T07:44:01Z
- New commits read: 1 —
91e7e8af"fix(pi): chain review round 1 - ping headers, systemd quoting, tests" (5 files, all in pi-package) - Read in full: 2 reviews, 1 comment, 0 inline comments (from the three files; the inline file is empty — the PR has no inline comments)
- New items since my last review: the fix commit and the author's round-1 reply comment. I also read reviewer 2's round-1 review in full now, after my own was posted.
- Verified the ping-header warning end to end:
has_headersreads only the provider's own entry and fails closed to "no warning" on an unreadable models.json; the warning shows in the chain question, in a re-setup plan of an already-chained provider, and in the replace question for a provider that stays chained; it is absent with--cache-strategy none. The new Python test asserts each of these. - Verified the systemd escaping by hand: applied each replace to a URL with
%b,$HOME, a quote and a backslash, and got the expected quoted string; checked the unit-file test asserts"--anthropic-upstream" "https://gw.example/team%%b$$x"inExecStart. launchd is untouched (plistProgramArgumentsis an array, no expansion). - Verified
stripsChatGPTFieldsagainst the old inline check and read its test. - Read the two new README blocks ("One answer for both providers", "A chain stays until uninstall") against the code: both describe behavior I traced in round 1, unchanged by the fix commit.
- Re-read the full new-commit diff and the final state of every changed region (
consent_question,has_headers,_systemd_quote,start_service,conflictWords,conflictPrompt, the handler, all new tests). - Did not run the tests (live tests not approved). The author reports Python 49 and Node 11 passing.
Conflicts were additions on both sides; each resolution keeps both: - pi-package/README.md: the chained-openai sentence from #1010 and the session-start bullet from this branch. - pi-package/scripts/test_pi_plugin.py: the Restart and ChainMode test classes. - pi-package/tests/context-guru.test.ts: one import list with the helpers of both changes, and both sets of tests. Python 63 pass, Node 26 pass, tsc strict clean. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…1014) TestDashboardAddsNoRequestLatencyWithContentCapture failed on loaded CI runners (on #930, #971, #996, #1010) because one pass of 40 paired samples was too noisy for the 45 ms budget. It now measures the guard in up to 3 rounds, and passes as soon as one round is in budget; a real slowdown fails all 3. Closes #1013. Behavior change: none. Test only (proxy/dash_test.go). Data dependence: none. Known limit (older than this PR): under heavy load, a 50 ms delay in capture.finish does not fail the test; filed as its own issue. Reviews: 2 offload reviews (GLM), round 2, both approve at 2fbb429. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
At each Pi session start, the Pi extension now checks the local proxy with one GET /healthz (5-second limit). If the proxy does not answer, it restarts the proxy's user service once and checks again. If the proxy is still down, Pi shows one warning, not only a connection error on every routed request. Behavior change: Pi users who installed context-guru with /context-guru setup, and only when a Pi model goes to the proxy. Old: nothing checked the proxy, and a down proxy showed only connection errors. New: the check, one restart, and one warning. No switch; pi --no-extensions turns off the whole extension, and /context-guru uninstall removes the install record and so the check. Owner's yes, 2026-11-10, in the integrator session: "1011 behavior change approved". Data dependence: metadata only. A bare GET /healthz to localhost with no body. It reads the install record and the model URLs Pi knows. No change to stored data. Reviews: 2 offload reviews (GLM), round 3 (owner granted round 3), both approve at 655a6a9. Round 3 reviewed the merge of main after #1010, which changed the same 5 pi-package files. Two later merges of main (1077d80 after #1012, d4124cd after #1014) change no #1011 code: their remerge-diff outside docs/data-dependence.md is 0 lines; the one doc conflict kept both rows. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…rged (#1046) #1010 and #1011 are merged, so the two "(open PR)" rows on the Pi and Claude Code comparison page now describe what main does. Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
- restart reads the install record again after it takes the lock. - setup and update write the config and the record under the restart lock. - The lock wait has a 40 s limit. restart reports result=busy; configure, setup and update refuse with reason=busy and write nothing. - With no fcntl (a state directory copied to Windows) there is no lock, and restart reports service=unsupported, not a traceback. - The extension gives configure 60 s, as restart has. A restart stopped at the 60 s limit says so, not "the restart did not run". - The headers warning says "set" for two providers, and the chained quota wording names the chained providers. - conflictWords joins with "; ", because a URL can hold a comma. - data-dependence: restart does not read the proxy URLs. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude (Anthropic AI) <[email protected]>
The review notes left on #1010, #1011 and #1049, for the Pi package: configure reads the install record again, conflictWords joins with "; " (a URL can hold a comma), and the data-dependence row says restart does not read the proxy URLs. Tests for the configure and update busy paths, and for each finding. Behavior change: none for users: the Pi package has no users yet (owner decision on #1049). Owner's yes, 2026-11-11, in the integrator session: "btw in the meantime 1058 is ready". Data dependence: no change. Metadata only; the docs row states it more exactly. Reviews: 2 offload reviews (GLM), round 2, both approve at 4da5bb4. The branch was then rewritten only to change the sign-off e-mail; the patch is identical (patch-id 563da3ea9c58 before and after). Assisted-By: Claude (Anthropic AI) <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
…0.2.12, Pi 0.1.1) Claude Code plugin 0.6.7 -> 0.7.2: - #981, #989, #1018, #1035: subscription band and savings show saved tokens. - #1038: insights drop the finding that credits a user's own removal. - #1039, #1040: dash and keep-alive fixes that touch the plugin files. Codex plugin 0.2.11 -> 0.2.12: - #1051: read the cache strategies and presets from the proxy. - The vendored cg.py gets the same plugin changes. Pi package 0.1.0 -> 0.1.1: - #1010: chain the proxy in front of an existing base URL. - #1011: check the proxy at session start and restart it once. - #1049, #1058: write the cache strategy by name; review fixes. OpenCode plugin (#483): new in v0.7.2, no version file, not changed. Bob plugin 0.1.0: no change since v0.7.1, not changed. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]> Signed-off-by: DAVID AMID <[email protected]>
Bump the plugin versions for v0.7.2. - Claude Code plugin 0.6.7 -> 0.7.2: #981, #989, #1018, #1035 (savings in tokens on a subscription), #1038, #1039, #1040, #1055 (cache strategies read from the proxy). - Codex plugin 0.2.11 -> 0.2.12: #1051 (cache strategies and presets read from the proxy), plus the vendored cg.py changes. - Pi package 0.1.0 -> 0.1.1: #1010, #1011, #1049, #1058, and the #1040 README line. - OpenCode plugin: new in v0.7.2 (#483), no version file. Its first start now downloads proxy v0.7.2 (was v0.7.1). Nothing compares against PINNED_VERSION; the floor stays "v0.7.1 or later". The README lines, the install guide and 3 tests follow. - Bob plugin: 0.1.0, no change since v0.7.1. Behavior change: the OpenCode plugin's first download is proxy v0.7.2, not v0.7.1. Owner's yes, 2026-11-11, in the integrator session: "option1 it is"; the version bumps: "I approve the version bumps for the plugins". Data dependence: none. Reviews: 3 offload review rounds (GLM; round 3 pre-approved by the owner). Both reviewers approve at 3cf6176, which is the PR head. Signed-off-by: DAVID AMID <[email protected]> Assisted-By: Claude Opus 5.5 <[email protected]>
Behavior change
models.jsonalready setsbaseUrlforanthropicoropenai(a company gateway, for example)./context-guru setuprefuses withbase_url_already_set. Nothing changes.setupwithout--on-conflictstill change nothing./context-guru uninstall(or the reset command) puts the oldbaseUrlback.Summary
A user behind a gateway can now put the proxy in front of that gateway. The gateway still gets every request, on the same path, with the same headers and key.
What changed
--anthropic-upstream/--openai-upstreamset from the oldbaseUrl. The provider entry keepsheaders,apiKeyand every other field. OnlybaseUrlchanges.baseUrlneeds the decision. The other one is routed as usual.setup --planprintsconsent_question_chain+confirm_command_chainandconsent_question_replace+confirm_command_replace. No plainconsent_questionon that path.chain_refused=<provider>:<reason>:baseUrlthat does not end in/v1(openai_path_not_v1)credentials_in_url), a query (query_in_url), or nothttp(s)(not_an_http_url)points_at_this_proxy)upstreams.configure,updateand a newsetupstart the proxy with them.proxy.yamlnames them in a comment line.routes=anthropic -> proxy -> https://gw...; openai -> proxy -> api.openai.com. The extension shows it./context-guru setupshows the choice withctx.ui.select. The Sign in with ChatGPT field removal skips a chainedopenaiprovider, because Pi sent those fields to that endpoint before.origin/mainalready treats it as ours throughown_urls. This PR adds a test only.How it was tested
python3 -m unittest discover -s scripts: 46 tests pass (16 new, inChainMode). They cover the paired plan lines, chain, replace, abort, refusal without the flag, a one-provider conflict, unchainable URLs, uninstall and the reset command restoring the gateway, and configure keeping the upstream.node --test tests/*.test.ts: 9 tests pass (2 new, forconflictPrompt).baseUrlhttp://127.0.0.1:18931/corp/anthropic-> the gateway gotPOST /corp/anthropic/v1/messageswithx-api-keyand the customx-corp-tenantheader.baseUrlhttp://127.0.0.1:18931/corp/openai/v1-> the gateway gotPOST /corp/openai/v1/responseswithAuthorization: Bearer ...andx-corp-tenant.models.jsonbyte-for-byte equal as JSON.Data dependence
None new. This is routing only: the proxy gets a different upstream URL. No row in
docs/data-dependence.mdchanges.Open questions
/anthropic/v1/messages(Pi sends?beta=true). That is the same today forapi.anthropic.com, so this PR does not change it. A gateway that needs the query would see a difference.baseUrlon one model (models.<id>.baseUrl) wins over the provider's. Setup does not read it, so that model goes direct, as before.Technical notes
--anthropic-upstreamand--openai-upstream(cmd/context-guru-proxy/main.go).upstream + "/v1/messages"andupstream + "/v1/responses"(proxy/proxy.goMux,doUpstream). Pi's SDKs sendbaseUrl + "/v1/messages"(Anthropic) andbaseUrl + "/responses"(OpenAI). So the Anthropic upstream is thebaseUrlas it is, and the OpenAI upstream is thebaseUrlwithout/v1.copyHeadersforwards every client header except hop-by-hop headers,x-context-guru-*andCookie. The service sets noANTHROPIC_API_KEY/OPENAI_API_KEY, so the proxy injects no key of its own.🤖 Generated with Claude Code