generated from BlackHatMagic/Template-Bare
feat: configure providers in plugin settings #4
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/provider-ui"
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
Summary
Adds Settings → Pi Chat → Providers so provider credentials and compatible endpoints can be managed without editing Pi's JSON files or leaving Obsidian.
Design Overview
auth.jsonandmodels.jsonin its agent directory as the source of truth. The settings UI edits those files directly, preserving unrelated keys and metadata.src/provider-store.tsreads/writes{providerId: {type, key, env}}credentials andmodels.jsonprovider definitions. Writes use a temp file plus rename and0600mode; provider IDs, URLs, API types, and model lists are validated. Local custom endpoints receive Pi's documentedapiKey: "local"placeholder when no key is supplied.PiChatSettingsTabgains the providers section;SettingsHostgainsrestartSession(); version bumped to0.3.0.Implementation Notes
PI_CODING_AGENT_DIRwhen present, otherwise~/.pi/agent./login; the panel explicitly manages API keys and compatible endpoints instead of pretending to implement provider OAuth flows.••••1234orcommand); configured API-key commands are not executed while listing.Testing Evidence
tests/provider-store.test.tscovers API-key save/list/mask, preserving unrelated entries, custom endpoint save/remove, local endpoints without keys,$schemapreservation, invalid IDs/URLs/model lists, and key-command masking.bun run check: typecheck + 30 tests pass.bun run build: passes.Documentation
Checklist (Feature-Specific)
Additional Notes
Pi code review
2 new actionable findings
src/provider-store.ts:142src/provider-store.ts:65Merged the candidate reviews of head
cf1218eagainst base83a31e0, retaining two evidence-supported defects in provider-file mutation and ID handling. Verification was read-only using repository code and the supplied diff; no tests were run, and Pi's external credential-resolution behavior was not independently verified.Change walkthrough
src/provider-store.ts,src/settings.ts,manifest.json,versions.jsontests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
cf1218ebf30eb7abb96f3bd039ffc8c21d26c6dawithproxy/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.@ -0,0 +62,4 @@}function validateId(id: string): string {const value = id.trim().toLowerCase();[P2] Lowercasing existing provider IDs prevents removal and key replacement
Quality: The panel lists existing provider IDs verbatim, but every mutation lowercases the selected ID before looking it up. For an existing mixed-case entry, Remove therefore targets a different property and reports success without removing the displayed provider; saving a replacement key creates a separate lowercase entry instead of updating the selected credential.
Trigger: Open the panel with an existing auth.json or models.json provider named, for example, Acme, then click Remove or save a replacement API key for that entry.
Impact: The configured endpoint or credential cannot be removed through the panel, and a replacement key is written under the wrong provider ID while the original credential remains unchanged.
Evidence: src/provider-store.ts:65 applies toLowerCase(), although PROVIDER_ID accepts uppercase letters. readProviderState preserves JSON property names when producing credential and endpoint IDs, and the settings callbacks pass those IDs directly to the mutation helpers. removeProvider then uses the normalized ID in case-sensitive membership checks and deletions at lines 179–191; saveApiKey likewise selects and replaces auth[id] at lines 141–142. The settings callbacks show success even when removal found no matching property.
@ -0,0 +139,4 @@const path = join(agentDir, "auth.json");const auth = await readJson<Record<string, StoredCredential>>(path, {});const previous = auth[id];await writeJson(path, { ...auth, [id]: { ...(previous && previous.type === "api_key" ? previous : {}), type: "api_key", key: value } });[P2] Concurrent provider saves can silently discard credentials
Quality: Provider mutations read and replace the entire configuration file without coordinating concurrent writers. When two saves read the same snapshot, the later replacement omits the other save's changes, even though both settings callbacks can report success. Renaming a temporary file does not prevent this lost-update race.
Trigger: Save different providers concurrently from two Obsidian vault windows sharing the default agent directory, or start overlapping saves from the enabled settings buttons.
Impact: A successfully saved credential or endpoint can disappear, leaving the affected provider unavailable after restart and requiring its configuration to be restored.
Evidence: src/provider-store.ts:140–142 reads auth.json and writes a replacement built from that snapshot without locking or conflict detection. saveCustomProvider and removeProvider use the same whole-file mutation pattern. The async Save callbacks in src/settings.ts neither serialize mutations nor disable the buttons while writes are pending, and piAgentDir defaults vaults to the shared ~/.pi/agent directory. The base settings implementation did not mutate these files.
Pi code review
0 new actionable findings
No new actionable findings. Previously reported issues, if any, are tracked below.
Earlier findings: 2 rechecked
src/provider-store.ts:65, first reported in review #307) — src/provider-store.ts:64–70 now trims and returns the provider ID without lowercasing it. Replacement and removal therefore address the same case-sensitive properties returned by readProviderState(); tests/provider-store.test.ts also covers replacing and removing MyProvider, although the test was not run during this review.src/provider-store.ts:142, first reported in review #307) — src/provider-store.ts:135–142 serializes operations within one module instance, fixing overlapping settings saves there. Separate vault windows still target the shared default agent directory with independent queues, while lines 149–151 retain snapshot-based whole-file replacement without cross-instance coordination; concurrent successful saves can therefore lose a credential or endpoint.Merged the candidate reviews against the pinned head and base, checking provider persistence, settings integration, and both previous findings. The mixed-case ID issue is fixed, but cross-vault concurrent writes remain unprotected; verification was read-only, with no tests, build, or live Obsidian/Pi checks run.
Change walkthrough
src/provider-store.ts,src/settings.ts,manifest.json,versions.jsontests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
e25b74357dc563e34ab2252103d5863247ad7978withproxy/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.Pi code review
1 new actionable finding
src/provider-store.ts:59Earlier findings: 1 rechecked
src/provider-store.ts:135, first reported in review #307) — Current src/provider-store.ts:145–177 adds withProviderLock(), acquiring the shared .pi-obsidian-provider.lock directory through atomic non-recursive mkdir before executing a mutation and releasing it in finally. saveApiKey(), saveCustomProvider(), and removeProvider() wrap their complete read-modify-write operations in that filesystem lock, including the endpoint's credential write. Independent vault instances therefore no longer rely solely on module-local Promise queues for the reported overlapping-save scenario; lock contention times out with an error rather than silently replacing an overlapping snapshot. This was verified statically, not exercised.Merged the candidate reviews against the supplied head/base comparison, retaining one directory-resolution defect and verifying the fix for the previously reported cross-vault save race. Verification was read-only: no checks were run, and findings dependent on unverified Pi credential precedence or lacking meaningful functional impact were suppressed.
Change walkthrough
src/provider-store.ts,src/settings.ts,manifest.json,versions.jsontests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
3b52bce28a1a6739119870812893ddee4083a8f7withproxy/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.@ -0,0 +56,4 @@const configured = env.PI_CODING_AGENT_DIR?.trim();if (configured) {const expanded = expandHome(configured);return isAbsolute(expanded) ? expanded : resolve(expanded);[P2] Relative agent directories target different files than the Pi child
Quality: A relative PI_CODING_AGENT_DIR is resolved against Obsidian's process working directory, but the Pi child receives the unchanged relative environment value and runs in the vault directory. When those working directories differ, the settings panel reads and modifies a different configuration directory, so restarting Pi does not apply the saved provider changes.
Trigger: Obsidian inherits a relative PI_CODING_AGENT_DIR such as ./pi-agent, its process working directory differs from the vault root, and Pi resolves the relative directory from its child working directory.
Impact: Saved credentials and endpoints remain unavailable to the running agent; removing a provider can alter an unrelated configuration directory while leaving the active credential intact.
Evidence: src/provider-store.ts:55–61 calls resolve(expanded) without the vault working directory. src/settings.ts calls readProviderState() with that default and passes state.agentDir to all save/remove operations. Conversely, src/main.ts defines the session cwd as the vault path, src/session.ts supplies that cwd and piEnvironment() to PiClient, src/launcher.ts preserves PI_CODING_AGENT_DIR unchanged, and src/pi-client.ts passes cwd and env directly to spawn. No shared directory normalization aligns these two paths.
Pi code review
0 new actionable findings
No new actionable findings. Previously reported issues, if any, are tracked below.
Earlier findings: 1 rechecked
src/provider-store.ts:59, first reported in review #309) — src/provider-store.ts:55–61 now accepts an explicit cwd and resolves relative PI_CODING_AGENT_DIR values with resolve(cwd, expanded). Both settings call sites, src/settings.ts:90 and :125, pass this.host.vaultPath || process.cwd(), matching the cwd getter in src/main.ts and the working directory forwarded through src/session.ts to PiClient's spawn options. Save/remove handlers use the resulting state.agentDir, so settings and the Pi child now target the same directory for the previously reported relative-path case. tests/provider-store.test.ts:17–19 covers resolution against an explicit vault directory; it was inspected but not run.Merged the candidate reviews of the provider-settings feature against the supplied base; no new finding met the evidence threshold, and the previous relative-directory defect is fixed. Verification was read-only: no tests or builds were run, and Pi credential precedence and platform-specific filesystem failure behavior could not be independently verified.
Change walkthrough
src/provider-store.ts,src/settings.ts,manifest.json,versions.jsontests/provider-store.test.tsREADME.mdpackage.jsonReview effort: 3/5.
Static observations (not validation results)
Reviewed
84946cf8e72f7e3ff11015993d8e8abd9aa59e78withproxy/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.