Local-first AI coding agent desktop: Electron + Rust host core + pi Agent Harness + user-installable plugins
TypeScript ai-agentcoding-agentdesktop-appelectronglobali18nlocal-firstmcppipi-agentpi-desktoppluginsreactrusttypescript
fix(shared): do not import pi `!command` apiKey as a literal secret
aharon9549690f7b89
diff --git a/docs/adr/0179-import-model-configuration.md b/docs/adr/0179-import-model-configuration.mdindex 70a25f842..908b7cecd 100644--- a/docs/adr/0179-import-model-configuration.md+++ b/docs/adr/0179-import-model-configuration.md@@ -53,6 +53,8 @@ credentials. Copying refresh tokens would be the wrong security boundary.4. **Secrets.** A stored API key, `env:` / `env_key` resolution, or`Authorization: Bearer` header is copied into the host secret store.Placeholder values (`YOUR_API_KEY`, `${VAR}`) are treated as missing.+ A pi `apiKey` or auth header written as a `!<shell command>` is never+ executed or stored; that provider is imported without a secret.OAuth auth.json entries and Codex `requires_openai_auth` tables withouta key are omitted or imported without a secret.diff --git a/packages/shared/src/model-config-import.test.ts b/packages/shared/src/model-config-import.test.tsindex 650e7526a..a5260ad66 100644--- a/packages/shared/src/model-config-import.test.ts+++ b/packages/shared/src/model-config-import.test.ts@@ -172,6 +172,44 @@ requires_openai_auth = true});describe("parsePiModelConfig", () => {+ it("imports without a secret when apiKey is a `!` shell command", () => {+ const command = "!/usr/bin/security find-generic-password -w -a me -s svc";+ for (const apiKey of [command, ` ${command} `]) {+ const drafts = parsePiModelConfig(+ {+ providers: {+ radius: {+ baseUrl: "https://api.example.com",+ api: "anthropic-messages",+ apiKey,+ models: [{ id: "pi-model" }],+ },+ },+ },+ {},+ );+ expect(drafts).toHaveLength(1);+ expect(drafts[0].secretValue).toBeUndefined();+ expect(drafts[0].hasSecret).toBe(false);+ expect(publicModelConfigCandidate(drafts[0]).hasSecret).toBe(false);+ }+ });++ it("ignores a `!` shell command in an auth header", () => {+ const drafts = parsePiModelConfig({+ providers: {+ radius: {+ baseUrl: "https://api.example.com",+ headers: { Authorization: "!security find-generic-password -w -s svc" },+ models: [{ id: "pi-model" }],+ },+ },+ });+ expect(drafts).toHaveLength(1);+ expect(drafts[0].secretValue).toBeUndefined();+ expect(drafts[0].hasSecret).toBe(false);+ });+it("reads ~/.pi/agent/models.json providers, env: keys, and limits", () => {const drafts = parsePiModelConfig({diff --git a/packages/shared/src/model-config-import.ts b/packages/shared/src/model-config-import.tsindex baa7b133d..02c30e445 100644--- a/packages/shared/src/model-config-import.ts+++ b/packages/shared/src/model-config-import.ts@@ -430,9 +430,14 @@ export function parsePiModelConfig(const baseUrl = firstString(record.baseUrl, record.baseURL, record.url);const apiStyle = resolveApiStyle(firstString(record.api, record.apiStyle, record.type));const headers = asRecord(record.headers);+ // pi resolves `"!<cmd>"` values by running the command at request time. The+ // importer never executes it and never stores the command text as a key, so+ // the provider is imported without a secret (`hasSecret: false`).const secret = firstSecret(- resolveSecret(record.apiKey ?? record.api_key, env),- secretFromAuthHeader(headers),+ isShellCommandSecret(record.apiKey ?? record.api_key)+ ? undefined+ : resolveSecret(record.apiKey ?? record.api_key, env),+ isShellCommandSecret(authHeaderValue(headers)) ? undefined : secretFromAuthHeader(headers),);const modelEntries = Array.isArray(record.models) ? record.models : [];const modelIds = uniqueModelIds(modelEntries.map(modelIdFromUnknown));@@ -900,14 +905,22 @@ function authApiKey(value: unknown): string | undefined {return firstString(record.key, record.apiKey, record.token);}-function secretFromAuthHeader(headers: unknown): string | undefined {+function isShellCommandSecret(raw: unknown): boolean {+ return typeof raw === "string" && raw.trim().startsWith("!");+}++function authHeaderValue(headers: unknown): string | undefined {const record = asRecord(headers);- const value = firstString(+ return firstString(record?.Authorization,record?.authorization,record?.["x-api-key"],record?.["X-Api-Key"],);+}++function secretFromAuthHeader(headers: unknown): string | undefined {+ const value = authHeaderValue(headers);if (!value) return undefined;const bearer = value.match(/^Bearer\s+(.+)$/i);return sanitizeSecret(bearer ? bearer[1] : value);