feat: configure providers in plugin settings #4

Merged
BlackHatMagic merged 5 commits from feat/provider-ui into master 2026-10-25 05:40:54 +00:00

PR Type Selection

  • 🎯 Feature - New capability or functionality

Summary

Adds Settings → Pi Chat → Providers so provider credentials and compatible endpoints can be managed without editing Pi's JSON files or leaving Obsidian.

  • Add or replace an API key for any provider ID.
  • Add/update an OpenAI-, Anthropic-, or Google-compatible endpoint with base URL, API type, optional key, and model IDs.
  • List and remove configured credentials/custom endpoints.
  • Restart Pi from the section to load the new auth/model catalog.
  • Secrets are masked in the UI and never written to Obsidian plugin data.

Design Overview

  • Core idea: Pi already treats auth.json and models.json in its agent directory as the source of truth. The settings UI edits those files directly, preserving unrelated keys and metadata.
  • Data structures / algorithms: src/provider-store.ts reads/writes {providerId: {type, key, env}} credentials and models.json provider definitions. Writes use a temp file plus rename and 0600 mode; provider IDs, URLs, API types, and model lists are validated. Local custom endpoints receive Pi's documented apiKey: "local" placeholder when no key is supplied.
  • Interfaces added/changed: PiChatSettingsTab gains the providers section; SettingsHost gains restartSession(); version bumped to 0.3.0.

Implementation Notes

  • Agent directory resolution: PI_CODING_AGENT_DIR when present, otherwise ~/.pi/agent.
  • OAuth/subscription sign-in still uses Pi's interactive /login; the panel explicitly manages API keys and compatible endpoints instead of pretending to implement provider OAuth flows.
  • Credentials are listed with type and a masked hint (••••1234 or command); configured API-key commands are not executed while listing.
  • Custom providers that also have an API key are shown once in the endpoint list with a "key saved" status.
  • Removing a provider removes both its auth entry and its custom endpoint definition.

Testing Evidence

  • Added tests: tests/provider-store.test.ts covers API-key save/list/mask, preserving unrelated entries, custom endpoint save/remove, local endpoints without keys, $schema preservation, invalid IDs/URLs/model lists, and key-command masking.
  • bun run check: typecheck + 30 tests pass.
  • bun run build: passes.

Documentation

  • README updated with provider configuration and OAuth limitation
  • Design doc added/updated
  • Code comments added where behavior is non-obvious

Checklist (Feature-Specific)

  • Issue(s) linked (or rationale if none)
  • Tests added and passing
  • No Lint / Style violations
  • No dead / Debug / Commented-Out code
  • Follows course integrity guidelines

Additional Notes

  • Review focus: auth/models file mutation safety, secret handling, provider validation, and whether the settings UI accurately reflects Pi's credential precedence.
## PR Type Selection - [x] 🎯 **Feature** - New capability or functionality ## Summary Adds **Settings → Pi Chat → Providers** so provider credentials and compatible endpoints can be managed without editing Pi's JSON files or leaving Obsidian. - Add or replace an API key for any provider ID. - Add/update an OpenAI-, Anthropic-, or Google-compatible endpoint with base URL, API type, optional key, and model IDs. - List and remove configured credentials/custom endpoints. - Restart Pi from the section to load the new auth/model catalog. - Secrets are masked in the UI and never written to Obsidian plugin data. ## Design Overview - **Core idea:** Pi already treats `auth.json` and `models.json` in its agent directory as the source of truth. The settings UI edits those files directly, preserving unrelated keys and metadata. - **Data structures / algorithms:** `src/provider-store.ts` reads/writes `{providerId: {type, key, env}}` credentials and `models.json` provider definitions. Writes use a temp file plus rename and `0600` mode; provider IDs, URLs, API types, and model lists are validated. Local custom endpoints receive Pi's documented `apiKey: "local"` placeholder when no key is supplied. - **Interfaces added/changed:** `PiChatSettingsTab` gains the providers section; `SettingsHost` gains `restartSession()`; version bumped to `0.3.0`. ## Implementation Notes - Agent directory resolution: `PI_CODING_AGENT_DIR` when present, otherwise `~/.pi/agent`. - OAuth/subscription sign-in still uses Pi's interactive `/login`; the panel explicitly manages API keys and compatible endpoints instead of pretending to implement provider OAuth flows. - Credentials are listed with type and a masked hint (`••••1234` or `command`); configured API-key commands are not executed while listing. - Custom providers that also have an API key are shown once in the endpoint list with a "key saved" status. - Removing a provider removes both its auth entry and its custom endpoint definition. ## Testing Evidence - Added tests: `tests/provider-store.test.ts` covers API-key save/list/mask, preserving unrelated entries, custom endpoint save/remove, local endpoints without keys, `$schema` preservation, invalid IDs/URLs/model lists, and key-command masking. - `bun run check`: typecheck + **30 tests** pass. - `bun run build`: passes. ## Documentation - [x] README updated with provider configuration and OAuth limitation - [ ] Design doc added/updated - [x] Code comments added where behavior is non-obvious ## Checklist (Feature-Specific) - [x] Issue(s) linked (or rationale if none) - [x] Tests added and passing - [x] No Lint / Style violations - [x] No dead / Debug / Commented-Out code - [x] Follows course integrity guidelines ## Additional Notes - Review focus: auth/models file mutation safety, secret handling, provider validation, and whether the settings UI accurately reflects Pi's credential precedence.
Add a Providers section that edits Pi's auth.json and models.json directly:
API keys for any provider ID, custom OpenAI/Anthropic/Google-compatible
endpoints with optional keys and model IDs, credential removal, and a restart
action. Secrets are masked, files are written atomically with 0600 mode, and
OAuth sign-in remains Pi's /login flow.
Code-Reviewer left a comment

Pi code review

2 new actionable findings

  • [P2] Concurrent provider saves can silently discard credentials — src/provider-store.ts:142
  • [P2] Lowercasing existing provider IDs prevents removal and key replacement — src/provider-store.ts:65

Merged the candidate reviews of head cf1218e against base 83a31e0, 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
Area Files Changes
Other code (4) src/provider-store.ts, src/settings.ts, manifest.json, versions.json Adds provider configuration discovery, credential masking, validation, and auth.json/models.json mutations. Adds provider lists, API-key and compatible-endpoint forms, removal actions, and a Pi restart button. Bumps the plugin version to 0.3.0. Registers Obsidian compatibility for version 0.3.0.
Tests (1) tests/provider-store.test.ts Adds tests for credential storage, masking, endpoint updates, metadata preservation, removal, and validation.
Documentation (1) README.md Documents provider configuration and the OAuth sign-in limitation.
Deployment & tooling (1) package.json Bumps the package version to 0.3.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 7 files, +485/-4.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed cf1218ebf30eb7abb96f3bd039ffc8c21d26c6da with proxy/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.

<!-- forgejo-pi-review:995107d2dc4c5c0248d60a38f3ce6dfec00014e341c868ae724a1c03ebc10c8b --> ## Pi code review **2 new actionable findings** - **[P2] Concurrent provider saves can silently discard credentials** — `src/provider-store.ts:142` - **[P2] Lowercasing existing provider IDs prevents removal and key replacement** — `src/provider-store.ts:65` Merged the candidate reviews of head cf1218e against base 83a31e0, 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. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (4) | `src/provider-store.ts`, `src/settings.ts`, `manifest.json`, `versions.json` | Adds provider configuration discovery, credential masking, validation, and auth.json/models.json mutations. Adds provider lists, API-key and compatible-endpoint forms, removal actions, and a Pi restart button. Bumps the plugin version to 0.3.0. Registers Obsidian compatibility for version 0.3.0. | | Tests (1) | `tests/provider-store.test.ts` | Adds tests for credential storage, masking, endpoint updates, metadata preservation, removal, and validation. | | Documentation (1) | `README.md` | Documents provider configuration and the OAuth sign-in limitation. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.3.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 7 files, +485/-4. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `cf1218ebf30eb7abb96f3bd039ffc8c21d26c6da` with `proxy/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();
Collaborator

[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.

**[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 } });
Collaborator

[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.

**[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.
Code-Reviewer left a comment

Pi code review

0 new actionable findings

No new actionable findings. Previously reported issues, if any, are tracked below.

Earlier findings: 2 rechecked
  • Resolved: Lowercasing existing provider IDs prevents removal and key replacement (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.
  • Still open (not reposted): Concurrent provider saves can silently discard credentials (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
Area Files Changes
Other code (4) src/provider-store.ts, src/settings.ts, manifest.json, versions.json Adds provider configuration reads, credential masking, validation, and file mutations serialized within one module instance. Adds provider credential and compatible-endpoint controls with an action invoking the existing Pi restart handler. Bumps the plugin version to 0.3.0. Records Obsidian compatibility for version 0.3.0.
Tests (1) tests/provider-store.test.ts Adds persistence, masking, validation, metadata preservation, mixed-case ID, and overlapping-save coverage.
Documentation (1) README.md Documents provider configuration, file locations, and the interactive OAuth limitation.
Deployment & tooling (1) package.json Bumps the package version to 0.3.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 7 files, +521/-4.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed e25b74357dc563e34ab2252103d5863247ad7978 with proxy/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.

<!-- forgejo-pi-review:6102ae3084674eb622ffbb60de5f5aa002670f03e5fb4fa788c40b1c00181074 --> ## Pi code review **0 new actionable findings** No new actionable findings. Previously reported issues, if any, are tracked below. <details> <summary>Earlier findings: 2 rechecked</summary> - **Resolved:** Lowercasing existing provider IDs prevents removal and key replacement (`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. - **Still open (not reposted):** Concurrent provider saves can silently discard credentials (`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. </details> 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. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (4) | `src/provider-store.ts`, `src/settings.ts`, `manifest.json`, `versions.json` | Adds provider configuration reads, credential masking, validation, and file mutations serialized within one module instance. Adds provider credential and compatible-endpoint controls with an action invoking the existing Pi restart handler. Bumps the plugin version to 0.3.0. Records Obsidian compatibility for version 0.3.0. | | Tests (1) | `tests/provider-store.test.ts` | Adds persistence, masking, validation, metadata preservation, mixed-case ID, and overlapping-save coverage. | | Documentation (1) | `README.md` | Documents provider configuration, file locations, and the interactive OAuth limitation. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.3.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 7 files, +521/-4. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `e25b74357dc563e34ab2252103d5863247ad7978` with `proxy/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.
Code-Reviewer left a comment

Pi code review

1 new actionable finding

  • [P2] Relative agent directories target different files than the Pi child — src/provider-store.ts:59
Earlier findings: 1 rechecked
  • Resolved: Concurrent provider saves across vaults can still discard credentials (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
Area Files Changes
Other code (4) src/provider-store.ts, src/settings.ts, manifest.json, versions.json Adds provider-file persistence, credential masking, validation, serialized mutations, and cross-process locking. Adds provider credential and endpoint management plus a Pi restart control. Bumps the plugin version to 0.3.0. Registers Obsidian compatibility for version 0.3.0.
Tests (1) tests/provider-store.test.ts Adds persistence, masking, metadata preservation, validation, and overlapping-save tests.
Documentation (1) README.md Documents provider configuration and the OAuth limitation.
Deployment & tooling (1) package.json Bumps the package version to 0.3.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 7 files, +555/-4.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 3b52bce28a1a6739119870812893ddee4083a8f7 with proxy/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.

<!-- forgejo-pi-review:d2a300fb515d3a2e32c12baa9aa4c8e86df1094a0d01615ad3aac7cd18087573 --> ## Pi code review **1 new actionable finding** - **[P2] Relative agent directories target different files than the Pi child** — `src/provider-store.ts:59` <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Concurrent provider saves across vaults can still discard credentials (`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. </details> 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. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (4) | `src/provider-store.ts`, `src/settings.ts`, `manifest.json`, `versions.json` | Adds provider-file persistence, credential masking, validation, serialized mutations, and cross-process locking. Adds provider credential and endpoint management plus a Pi restart control. Bumps the plugin version to 0.3.0. Registers Obsidian compatibility for version 0.3.0. | | Tests (1) | `tests/provider-store.test.ts` | Adds persistence, masking, metadata preservation, validation, and overlapping-save tests. | | Documentation (1) | `README.md` | Documents provider configuration and the OAuth limitation. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.3.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 7 files, +555/-4. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `3b52bce28a1a6739119870812893ddee4083a8f7` with `proxy/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);
Collaborator

[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.

**[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.
Code-Reviewer left a comment

Pi code review

0 new actionable findings

No new actionable findings. Previously reported issues, if any, are tracked below.

Earlier findings: 1 rechecked
  • Resolved: Relative agent directories target different files than the Pi child (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
Area Files Changes
Other code (4) src/provider-store.ts, src/settings.ts, manifest.json, versions.json Adds provider-file persistence, credential masking, validation, serialized mutations, and cross-window locking. Adds provider credential and compatible endpoint management, plus a Pi restart action. Bumps the plugin version to 0.3.0. Records Obsidian compatibility for version 0.3.0.
Tests (1) tests/provider-store.test.ts Adds coverage for persistence, masking, metadata preservation, validation, and relative directory resolution.
Documentation (1) README.md Documents provider configuration and the limitation to API keys rather than OAuth sign-in.
Deployment & tooling (1) package.json Bumps the package version to 0.3.0.

Review effort: 3/5.

Static observations (not validation results)
Observation Detail
Diff size 7 files, +562/-4.
Binary changes No binary changes reported by this diff.
Credential patterns No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit.

Reviewed 84946cf8e72f7e3ff11015993d8e8abd9aa59e78 with proxy/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.

<!-- forgejo-pi-review:c41d6da2c55b34216a8bc5c27481abdefc3177d02034e3e503d0a24ced2a7389 --> ## Pi code review **0 new actionable findings** No new actionable findings. Previously reported issues, if any, are tracked below. <details> <summary>Earlier findings: 1 rechecked</summary> - **Resolved:** Relative agent directories target different files than the Pi child (`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. </details> 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. <details> <summary>Change walkthrough</summary> | Area | Files | Changes | | --- | --- | --- | | Other code (4) | `src/provider-store.ts`, `src/settings.ts`, `manifest.json`, `versions.json` | Adds provider-file persistence, credential masking, validation, serialized mutations, and cross-window locking. Adds provider credential and compatible endpoint management, plus a Pi restart action. Bumps the plugin version to 0.3.0. Records Obsidian compatibility for version 0.3.0. | | Tests (1) | `tests/provider-store.test.ts` | Adds coverage for persistence, masking, metadata preservation, validation, and relative directory resolution. | | Documentation (1) | `README.md` | Documents provider configuration and the limitation to API keys rather than OAuth sign-in. | | Deployment & tooling (1) | `package.json` | Bumps the package version to 0.3.0. | Review effort: **3/5**. </details> <details> <summary>Static observations (not validation results)</summary> | Observation | Detail | | --- | --- | | Diff size | 7 files, +562/-4. | | Binary changes | No binary changes reported by this diff. | | Credential patterns | No matches after excluding known examples/placeholders. Added-line heuristics only; not a security audit. | </details> --- Reviewed `84946cf8e72f7e3ff11015993d8e8abd9aa59e78` with `proxy/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.
BlackHatMagic deleted branch feat/provider-ui 2026-10-25 05:40:54 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
BlackHatMagic/Pi-Obsidian!4
No description provided.