generated from BlackHatMagic/Template-Bare
fix: Flatpak provider auth and provider UI #5
Loading…
Reference in a new issue
No description provided.
Delete branch "fix/provider-ui-followup"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
PR Type Selection
Problem
On silverquill, Pi works from the terminal but the Obsidian plugin fails with
API key auth failed for provider proxy: authHeader requires a resolved API key.Root cause: Obsidian is a Flatpak. Flatpak sets
XDG_STATE_HOMEto~/.var/app/md.obsidian.Obsidian/.local/state, so the provider-proxy extension looks for its token there. Terminal Pi uses~/.local/state/provider-proxy/token. The plugin inherited the sandbox state path, so Pi registeredproxywith an empty key.The provider panel also only listed
auth.json/models.json, missing extension providers likeproxy; endpoints were not editable; and model IDs had to be typed as a comma-separated list.Fix
XDG_STATE_HOMEback to~/.local/statefor the Pi child. This lets Pi use its own extension auth exactly as terminal Pi does.proxy) in Settings. Extension-owned providers are read-only./modelsendpoint, with bearer,x-api-key(Anthropic), orx-goog-api-key(Google) auth.Testing
XDG_STATE_HOMEmapping and provider model discovery.bun run check: 35 tests pass.bun run build: passes.~/.local/state/provider-proxy/tokenand is readable inside the Flatpak sandbox; only the redirected state path caused the mismatch.Additional Notes
OAuth still uses Pi's
/login; this PR does not reimplement provider auth. Version 0.4.0.Pi code review
2 new actionable findings
src/provider-store.ts:276src/provider-store.ts:268Merged the candidate reviews against the pinned head and base, retaining two distinct model-discovery defects and deduplicating the Google-response finding. Verification was read-only and static; no tests, builds, or Obsidian/Flatpak runtime checks were run.
Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
91a7a78003df6dbf37a988048871ed820b38e81bwithproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +265,4 @@headers.authorization = `Bearer ${key.trim()}`;}}const response = await fetch(url, { headers, signal: AbortSignal.timeout(15_000) });[P2] Renderer CORS restrictions block adding otherwise usable endpoints
[Quality] Model discovery uses the Obsidian renderer's global fetch, requiring the provider to allow Obsidian's origin through CORS. An endpoint usable by the Pi CLI can therefore fail discovery in Settings. Since discovery is now mandatory for new endpoints, this prevents saving those endpoints rather than merely disabling an optional refresh.
Trigger: Add an OpenAI-compatible endpoint whose /models response does not allow Obsidian's renderer origin through CORS, then click Fetch models or Add endpoint.
Impact: Users cannot configure an otherwise working local or remote Pi endpoint through Settings; the previous manual-model workflow did not impose browser-origin access requirements.
Evidence: src/provider-store.ts:268 calls unqualified global fetch without importing a Node HTTP implementation or using Obsidian's CORS-independent request API. src/settings.ts imports discoverModels directly into PluginSettingTab and awaits it before saving whenever a new endpoint's customModels array is empty. The catch handler only displays a notice, and the former manual model input is gone. The added Bun test exercises server-side fetch, not the deployed renderer's CORS behavior.
@ -249,0 +273,4 @@: [];const ids = entries.flatMap((entry) => {if (typeof entry === "string") return [entry];if (typeof entry === "object" && entry !== null && "id" in entry && typeof entry.id === "string") return [entry.id];[P2] Google model discovery discards native ListModels responses
[Compliance/Quality] Google's ListModels response identifies models with a name such as "models/gemini-…", not an id. Although discovery accepts the top-level models array and supplies Google's authentication header, it discards every native Google entry and throws "Provider returned no model IDs." Removing manual model entry makes this failure block adding these endpoints.
Trigger: Select google-generative-ai with a valid key and a Google Generative Language API base URL such as https://generativelanguage.googleapis.com/v1beta, then click Fetch models or Add endpoint, assuming the request succeeds.
Impact: Users cannot add endpoints using Google's native model-list format through Settings, and existing Google endpoints cannot refresh their model catalog.
Evidence: src/provider-store.ts:271-280 accepts payload.models but retains only bare strings or objects with a string id; Google's name-only entries produce an empty list and reach the throwing guard. In src/settings.ts, new endpoints initialize customModels to an empty array, and the save handler awaits fetchCustomModels before saveCustomProvider. At the base commit, the form accepted manually entered model IDs without requiring discovery.
Pi code review
3 new actionable findings
src/provider-store.ts:266src/settings.ts:243src/settings.ts:284Earlier findings: 2 rechecked
src/provider-store.ts:268, first reported in review #313) — Current src/provider-store.ts imports node:http and node:https at lines 1-2, uses their request implementations in requestJson, and calls requestJson from discoverModels at line 310. Discovery no longer uses renderer fetch, removing the reported renderer-CORS dependency; Obsidian runtime behavior was not exercised.src/provider-store.ts:276, first reported in review #313) — Current src/provider-store.ts:317 accepts entries with a string name and strips the models/ prefix, so native Google ListModels entries are no longer discarded. tests/provider-store.test.ts includes a name-only Google response and expects the corresponding unprefixed model IDs; the test was inspected but not run.Merged the candidate reviews of head
432e6caagainst base70c11315, verifying the provider-discovery and Settings findings against current code and rechecking both previous findings. This was a read-only static review; no tests, builds, or Obsidian/Flatpak runtime checks were run.Change walkthrough
README.mdmanifest.json,src/launcher.ts,src/main.ts,src/provider-store.ts(+2 more)package.jsontests/launcher.test.ts,tests/provider-store.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
432e6ca00ed83d3dcbd59d3e0ae5a410eabd3f70withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +263,4 @@if (status >= 300 && status < 400 && response.headers.location && redirects < 5) {response.resume();const next = new URL(response.headers.location, parsed).toString();requestJson(next, headers, redirects + 1).then(resolve, reject);[P1] Model-list redirects forward credentials across origins
[Quality/Security] Redirect handling forwards all authentication headers to the redirect destination without checking its origin or preventing an HTTPS-to-HTTP downgrade. Fetching a model list can therefore disclose the provider's API key to another service or transmit it in plaintext.
Trigger: Click Fetch models or Add endpoint for an authenticated endpoint whose /models response redirects to a different origin or from HTTPS to HTTP.
Impact: The redirected service receives the provider credential, potentially enabling unauthorized API usage and charges; an HTTP downgrade also exposes it to network observers.
Evidence: src/provider-store.ts:263-266 resolves Location and calls requestJson(next, headers, redirects + 1), preserving the complete header object. discoverModels at lines 300-307 populates authorization, x-api-key, or x-goog-api-key, and the Settings caller invokes it directly. The redirect-count limit does not restrict destination origins or transport security. The base implementation made no model-discovery requests.
@ -211,0 +240,4 @@cls: "pi-chat-diagnostics-note",});const fetchCustomModels = async (): Promise<string[]> => {const key = customKey.trim() || (editing ? await storedApiKey(state.agentDir, editing.id) ?? "" : "");[P2] Adding an endpoint ignores its already-saved API key
[Quality] Model discovery only falls back to the saved credential when editing an existing endpoint. If a user saves a provider's API key first and then adds its endpoint with the key field blank, discovery sends no authentication and blocks saving despite the credential already being present.
Trigger: Save a literal API key using Add or update an API key, then add an authenticated compatible endpoint with the same provider ID while leaving the endpoint's API key field blank.
Impact: The endpoint cannot be added through this workflow because mandatory discovery fails authentication; the user must supply the same credential again.
Evidence: src/settings.ts:243 calls storedApiKey only when editing is non-null, so a new endpoint uses an empty key regardless of customId's saved credential. New endpoints start with an empty customModels array, and line 284 requires discovery to succeed before saveCustomProvider runs. The separate Save API key action writes auth.json through saveApiKey. At base, saving an endpoint accepted manually supplied model IDs without requiring an authenticated discovery request.
@ -237,0 +281,4 @@})).addButton((button) => button.setButtonText(editing ? "Save endpoint" : "Add endpoint").setCta().onClick(async () => {try {const models = customModels.length ? customModels : await fetchCustomModels();[P2] Changing the endpoint URL retains the previous server's models
[Quality] The discovered model list is cached independently of the endpoint fields. Changing the base URL after fetching models, or while editing an existing endpoint, leaves the old list intact, and Save associates it with the new server without fetching that server's catalog.
Trigger: Fetch models from endpoint A, change the Base URL to endpoint B with different model IDs, and click Add endpoint; alternatively, edit an existing endpoint's URL and click Save endpoint without explicitly fetching again.
Impact: Pi's models.json contains model IDs unavailable at the saved endpoint, causing those model selections to fail until the user refreshes and saves the catalog.
Evidence: src/settings.ts:237 prepopulates customModels when editing, and fetchCustomModels replaces it with discovery results. The Base URL handler at line 257 updates only customUrl, while line 284 skips discovery whenever customModels is nonempty. saveCustomProvider persists those IDs with the changed baseUrl, validating only that the list is nonempty. The base form required explicit model entry rather than automatically reusing a previously discovered catalog.
Pi code review
1 new actionable finding
src/provider-store.ts:252Earlier findings: 3 rechecked
src/settings.ts:284, first reported in review #314) — src/settings.ts:242-261 now clears cached models when endpoint fields change, fixing changes made after discovery completes. However, lines 248-249 still publish an in-flight request's results unconditionally after such a change, and lines 288-296 can save that stale catalog with the new endpoint URL, producing unavailable model selections. The finding is updated to this remaining trigger.src/settings.ts:243, first reported in review #314) — src/settings.ts:247 now calls storedApiKey(state.agentDir, editing?.id ?? customId), so adding a new endpoint with a blank key falls back to its provider ID's saved literal auth.json credential even when editing is null.src/provider-store.ts:266, first reported in review #314) — src/provider-store.ts:270-278 rejects redirects whose host, including port, differs and rejects HTTPS-to-non-HTTPS redirects before recursively forwarding authentication headers. This blocks the previously reported cross-host disclosure and HTTPS downgrade paths; the added cross-host rejection test was inspected but not run.Merged the candidate reviews of the Flatpak environment fix, provider settings, endpoint editing, and model discovery against base
70c11315and head8b1d0f39, retaining two evidence-supported defects and rechecking all three previous findings. Verification was limited to repository inspection; no tests, builds, or live Flatpak/provider checks were run.Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
8b1d0f39bfe0a35c3c399509749df1e96b7195fdwithproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -247,2 +249,4 @@}export async function storedApiKey(agentDir: string, providerId: string): Promise<string | undefined> {const auth = await readJson<Record<string, StoredCredential>>(join(agentDir, "auth.json"), {});[P2] Endpoint discovery ignores credentials stored in models.json
[Quality] Editing an existing endpoint with a blank key promises to keep its saved credential, but discovery only looks in auth.json. An authenticated endpoint whose apiKey is configured in models.json cannot refresh its catalog without the user supplying the credential again.
Trigger: Edit an existing compatible endpoint with a literal apiKey in models.json and no corresponding auth.json entry, leave API key blank, and click Fetch models. Changing its Base URL also makes Save require discovery.
Impact: Catalog refresh fails authentication, and endpoint URL changes cannot be saved through the advertised keep-saved-key workflow despite the endpoint already having valid credentials.
Evidence: src/settings.ts:247 resolves a blank key exclusively through storedApiKey, whose implementation at src/provider-store.ts:251-255 reads only auth.json. readProviderState omits models.json's apiKey from the editing state, while saveCustomProvider preserves an existing string provider.apiKey, demonstrating support for that credential location. discoverModels sends no authentication when the lookup returns empty. At base, endpoint updates accepted manually supplied model IDs and preserved the existing apiKey without requiring discovery.
Pi code review
2 new actionable findings
src/provider-store.ts:254src/provider-store.ts:318Earlier findings: 2 rechecked
src/settings.ts:249, first reported in review #314) — Current src/settings.ts:244-248 increments discoveryGeneration and clears cached models on field changes. fetchCustomModels captures the generation at line 250 and checks it at lines 256-258 after discovery, throwing before assigning or returning models when the fields changed. The reported stale-response sequence can no longer repopulate the cache or continue the awaiting save.src/provider-store.ts:252, first reported in review #315) — Current src/settings.ts:252-254 falls back from the entered key and storedApiKey to storedEndpointKey. Current src/provider-store.ts:309-315 reads models.providers[providerId].apiKey and returns a saved literal credential, fixing the reported discovery failure for models.json-only literal keys.Aggregated the three candidate reviews of head
6e8d7a6against base70c1131, verifying the supported findings and both previous findings against repository code. Verification was read-only; tests, typechecking, builds, and live Pi/Obsidian/Flatpak behavior were not run.Change walkthrough
README.mdmanifest.json,src/launcher.ts,src/main.ts,src/provider-store.ts(+2 more)package.jsontests/launcher.test.ts,tests/provider-store.test.tsReview effort: 3/5.
Static observations (not validation results)
Reviewed
6e8d7a6715354fb3b94ced7e5c02198e0953c4d0withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +251,4 @@export async function storedApiKey(agentDir: string, providerId: string): Promise<string | undefined> {const auth = await readJson<Record<string, StoredCredential>>(join(agentDir, "auth.json"), {});const key = auth[providerId]?.key;return typeof key === "string" && !key.startsWith("!") ? key.trim() || undefined : undefined;[P2] Mandatory discovery blocks command-backed endpoint credentials
[Quality] Endpoint saving now requires model discovery, but discovery discards saved command-backed credentials. Entering the command directly in the endpoint form instead sends the command text as the authentication header, so neither path authenticates successfully.
Trigger: Add an authenticated compatible endpoint using a command-backed key, or edit an existing endpoint with such a saved key and change its Base URL while leaving the key field blank.
Impact: Users relying on Pi's command-backed credentials cannot add or change authenticated endpoints through this form without extracting a literal secret or editing configuration outside the plugin.
Evidence: src/provider-store.ts:251-255 excludes auth.json keys beginning with '!'; storedEndpointKey at lines 309-315 also excludes command credentials. src/settings.ts:250-255 uses those helpers unless customKey is nonempty, which is passed directly to discoverModels and placed in an authentication header. Field changes clear customModels, and line 298 requires successful discovery before saving. The existing 'masks key commands without executing them' test establishes command credentials as a supported stored form; the base settings workflow saved manually supplied model IDs and passed the credential to Pi without making this HTTP request.
@ -249,0 +315,4 @@}export async function discoverModels(baseUrl: string, api: ProviderApi, key: string): Promise<string[]> {const url = `${validateUrl(baseUrl)}/models`;[P2] Anthropic discovery omits the required version path
[Quality] discoverModels appends '/models' uniformly, but an Anthropic SDK-style base URL is the origin without '/v1'. For the canonical Anthropic endpoint, discovery therefore requests https://api.anthropic.com/models instead of https://api.anthropic.com/v1/models, blocking the discovery-dependent save workflow.
Trigger: Select anthropic-messages with base URL https://api.anthropic.com and a valid key, then add the endpoint or change an existing endpoint field and save.
Impact: Adding a canonical Anthropic endpoint or saving changed endpoint fields fails because discovery requests the wrong route and there is no manual model-list fallback.
Evidence: src/provider-store.ts:318 constructs
${validateUrl(baseUrl)}/modelswithout an Anthropic-specific path, although lines 322-325 supply Anthropic authentication headers. Anthropic's canonical model-list route is '/v1/models', while its SDK base URL omits '/v1'. src/settings.ts clears the model cache on field changes and line 298 awaits discovery when that cache is empty; requestJson rejects non-2xx responses. The base workflow accepted manually entered model IDs and did not require this route to succeed.Pi code review
1 new actionable finding
src/settings.ts:255Earlier findings: 2 rechecked
src/provider-store.ts:318, first reported in review #316) — Current discoverModels in src/provider-store.ts constructs ${base}/v1/models for anthropic-messages unless the validated base already ends in /v1. A canonical https://api.anthropic.com base therefore reaches the required route, and the added Anthropic discovery test asserts the /v1/models path; the test was inspected but not run.src/provider-store.ts:254, first reported in review #316) — Current resolveCredential in src/provider-store.ts executes !-prefixed commands and returns trimmed stdout. Both storedApiKey and storedEndpointKey use this resolver, and discoverModels also resolves directly entered credentials before constructing authentication headers, fixing the discarded or literal-command behavior. The added Anthropic test covers a directly entered command-backed key; it was inspected but not run.Merged the candidate reviews for head
09838a4against base70c1131, verifying the credential-routing finding and both prior findings against current code. One new bug remains and both prior findings are resolved; verification was static only, with no tests, builds, or Flatpak runtime checks executed.Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
09838a4261fe649efc7e4834ce41479319bf844dwithproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -211,0 +252,4 @@const key = customKey.trim()|| (await storedApiKey(state.agentDir, providerId) ?? "")|| (await storedEndpointKey(state.agentDir, providerId) ?? "");const models = await discoverModels(customUrl, customApi, key);[P2] Changing providers during credential resolution can disclose the previous provider's key
[Quality] Model discovery captures the provider ID before awaiting credential resolution but reads the endpoint URL and API type afterward. Changing the form during that wait sends the original provider's resolved secret to the newly entered endpoint; the generation check rejects the result only after the authenticated request has completed.
Trigger: In the Add endpoint form, select a provider ID with a saved command-backed key that takes time to resolve, click Fetch models, then change the Provider ID and Base URL to another provider before resolution finishes.
Impact: The original provider's API key can be disclosed to an unrelated provider or local service even though the operation subsequently reports that the endpoint changed.
Evidence: src/settings.ts:249-255 captures providerId, awaits storedApiKey/storedEndpointKey, then calls discoverModels(customUrl, customApi, key) using mutable form values. The controls at lines 267-281 remain editable and only invalidate the model generation; the generation guard at lines 256-258 runs after discovery. src/provider-store.ts resolves command-backed credentials asynchronously with a 10-second timeout and attaches the resolved key to the supplied destination. Its redirect guard does not help because the changed URL is the initial destination. The base settings workflow did not issue a discovery request.
Pi code review
2 new actionable findings
src/provider-store.ts:347src/provider-store.ts:258Earlier findings: 1 rechecked
src/settings.ts:255, first reported in review #317) — Current src/settings.ts:249-257 snapshots endpointUrl, endpointApi, providerId, and enteredKey before awaiting stored credential resolution, then calls discoverModels(endpointUrl, endpointApi, key). Changing the form during credential resolution no longer redirects the captured provider's key to a newly entered destination; the generation check at lines 258-260 rejects stale results.Aggregated the three candidate reviews against the pinned base and head, retaining two evidence-supported correctness findings and confirming that the previous credential-disclosure issue is fixed. Verification was limited to repository reads; no tests, builds, live provider requests, or Flatpak runtime checks were run.
Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
69b8b5349fd3ee7dabda49744e0fa0fc0aa798d4withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +255,4 @@const key = value?.trim();if (!key || key === "local") return undefined;if (key.startsWith("!")) {try {[P2] Discovery runs credential commands outside Pi's working environment
[Quality] Command-backed keys execute with Obsidian's inherited environment and working directory rather than those used for the Pi child. A credential command that works in Pi can therefore fail during discovery, which is now required before adding an endpoint or saving changed endpoint fields.
Trigger: GUI-launched Obsidian lacks a mise-managed Node executable on PATH, and an entered or stored credential command invokes node; alternatively, the credential command uses a script relative to the vault root while Obsidian's working directory differs.
Impact: Model discovery fails with a credential-command error, blocking endpoint creation or updates despite the credential command working in the spawned Pi process.
Evidence: src/provider-store.ts:258 calls execAsync with only timeout and maxBuffer, inheriting process.env and process.cwd(). In contrast, src/session.ts constructs PiClient with the vault working directory and piEnvironment(), and src/pi-client.ts passes those values to spawn. src/launcher.ts augments Pi's PATH with discovered mise binaries and common installation directories. The settings discovery caller supplies neither that environment nor the vault working directory; unlike the base form, it executes credential commands before saving endpoint changes.
@ -249,0 +344,4 @@headers.authorization = `Bearer ${resolvedKey}`;}}const payload = await requestJson(url, headers);[P2] Paginated discovery drops models when endpoints are refreshed
[Quality] Discovery reads only the first response page, ignoring Google nextPageToken and Anthropic has_more/last_id pagination. Saving then replaces the endpoint's model array with that incomplete result. With manual model entry removed, later-page models cannot be configured through the panel, and refreshing an existing endpoint can remove previously configured models.
Trigger: Add an endpoint or fetch and save an existing endpoint whose model list spans multiple pages, with a desired or previously configured model on a later page.
Impact: Later-page models are omitted from the saved catalog, and refreshing and saving can delete their existing configuration and metadata.
Evidence: src/provider-store.ts:347-359 makes one request, extracts only payload.data or payload.models, and returns those IDs without following pagination. src/settings.ts:257-263 assigns that result to customModels, and its save handler passes the list to saveCustomProvider. src/provider-store.ts:210-216 constructs the replacement models array solely from supplied IDs, retaining metadata only for IDs still present. The base settings form allowed model IDs to be entered directly.
Pi code review
1 new actionable finding
src/provider-store.ts:265Earlier findings: 2 rechecked
src/provider-store.ts:258, first reported in review #318) — resolveCredential now calls execAsync with the supplied cwd and env: piEnvironment(). The settings discovery flow passes this.host.vaultPath || process.cwd() through storedApiKey, storedEndpointKey, and discoverModels, addressing the reported working-directory and augmented-PATH mismatch with the Pi child.src/provider-store.ts:347, first reported in review #318) — discoverModels now accumulates model IDs across a bounded pagination loop, following Google's nextPageToken through pageToken and Anthropic's has_more/last_id through after_id before deduplicating the result. The reported first-page-only behavior is fixed in the current code; pagination was inspected statically, not exercised.Merged the candidate reviews of head
1302ae8against base70c1131, covering Flatpak environment handling, provider settings, endpoint editing, and model discovery. Verification was static and read-only; tests, builds, live provider behavior, and the installed Pi credential resolver could not be exercised.Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
1302ae845a069591a4724c2d188218b88d96c1b0withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +262,4 @@throw new Error(`API key command failed: ${error instanceof Error ? error.message : String(error)}`);}}const match = key.match(/^\$\{?([A-Za-z_][A-Za-z0-9_]*)\}?$/);[P2] Discovery sends bare environment-variable names as API keys
[Quality] Pi supports bare environment-variable names in credential configuration, but the new resolver only looks up dollar-prefixed references. An existing endpoint using an environment-backed key therefore sends the variable name itself during discovery rather than the credential that Pi uses.
Trigger: An existing models.json endpoint has an apiKey such as MY_PROVIDER_API_KEY, that variable is present in Obsidian's environment with the actual credential, and the user fetches models or changes endpoint fields and saves without entering a replacement key.
Impact: Authenticated model discovery fails, preventing catalog refresh and blocking endpoint updates that require a fresh model list.
Evidence: src/provider-store.ts:265-266 returns non-command values literally unless they match the dollar-prefixed expression. storedEndpointKey passes models.json apiKey through this resolver, and src/settings.ts:255-258 uses that result when no entered or auth.json key is available. discoverModels then places the unresolved name in the authentication header. The base settings form saved supplied model IDs without authenticating against the model-list endpoint, so this discovery requirement introduces the incompatibility.
Pi code review
2 new actionable findings
src/settings.ts:255src/provider-store.ts:358Earlier findings: 1 rechecked
src/provider-store.ts:265, first reported in review #319) — Current src/provider-store.ts:267 recognizes bare uppercase environment-variable names and returns their nonempty process.env value before falling back to a literal. Both storedApiKey and storedEndpointKey use this resolver, so the reported MY_PROVIDER_API_KEY trigger now resolves to the actual credential before discovery constructs its authentication header.Merged the candidate reviews for head
20a25a7against base70c1131, validating the reported discovery issues and prior finding against the supplied diff and available surrounding code. Verification was read-only and static; no tests or builds were run, and live Obsidian/provider behavior was not exercised.Change walkthrough
src/launcher.ts,src/main.ts,src/provider-store.ts,src/settings.ts(+2 more)tests/launcher.test.ts,tests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
20a25a738b44b97453ae07253e682afa2b3ec189withproxy/glm-5.3-flash + proxy/deepseek-v4.1-flash + proxy/gpt-6.1-sol → proxy/gpt-6.1-sol. Automated advisory review; no project commands or tests were executed.@ -249,0 +355,4 @@: [];for (const entry of entries) {if (typeof entry === "string") ids.push(entry);else if (typeof entry === "object" && entry !== null && "id" in entry && typeof entry.id === "string") ids.push(entry.id);[P2] Discovery registers non-chat models as selectable chat models
[Quality] Discovery treats every returned model ID as compatible with the selected chat API. Mixed catalogs such as OpenAI's /v1/models include embedding, transcription, and image-generation models, which are then saved as chat models without a filtering or selection step.
Trigger: A user adds or refreshes an OpenAI-compatible endpoint whose model catalog includes non-chat models, saves it, restarts Pi, and selects one of those models in the chat header.
Impact: The chat selector offers models that cannot handle its requests, causing prompts using those selections to fail. Unlike the previous manual model list, the new settings form provides no way to exclude those entries.
Evidence: src/provider-store.ts:356-359 collects every entry's ID or name without checking capabilities. src/settings.ts assigns the entire discovery result to customModels and passes it to saveCustomProvider, which persists every ID under the selected API at src/provider-store.ts:211-217. PiSession.hydrate loads get_available_models into state.models; mergeModels only sorts them, and src/chat-view.ts renderControls exposes every loaded model as an option. The base form allowed users to supply only compatible model IDs.
@ -211,0 +252,4 @@const endpointApi = customApi;const providerId = editing?.id ?? customId;const enteredKey = customKey;const key = enteredKey.trim()[P2] Adding an endpoint silently forwards an existing provider's key
[Quality/security] Discovery falls back to stored credentials using the typed provider ID even when adding a new endpoint. Consequently, leaving the optional key blank can send an existing provider secret to the newly entered host merely by clicking Fetch models, before any endpoint configuration is saved.
Trigger: A user has an API key saved for a provider ID such as openai, enters that ID in Add a compatible endpoint with a different gateway or compatible-server URL, leaves the API key blank, and clicks Fetch models or Add endpoint.
Impact: The new host receives the existing provider credential without the user entering that credential or explicitly choosing to reuse it.
Evidence: src/settings.ts:253-258 selects editing?.id ?? customId and unconditionally falls back to storedApiKey and storedEndpointKey when the entered key is blank. src/provider-store.ts:271-274 reads auth.json by that ID, and discoverModels attaches the result as an authentication header to the initial URL. requestJson's cross-host redirect guard only constrains redirects, not this initial destination. The form describes blank-key retention specifically for editing; the base settings flow saved manually supplied models without making this discovery request.