pi-cliproxyapi 0.3.4 → 0.3.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -83,15 +83,15 @@ Then run `/cliproxy-setup` to configure your proxy endpoint.
83
83
 
84
84
  ## Config
85
85
 
86
- `~/.config/pi-cliproxyapi/config.json` — created by `/cliproxy-setup`, editable by hand:
86
+ `~/.pi/agent/pi-cliproxyapi/config.json` — created by `/cliproxy-setup`, editable by hand. If only the legacy `~/.config/pi-cliproxyapi/config.json` exists, an installed plugin moves it here once; a local checkout copies it and retains the legacy file.
87
87
 
88
88
  ```jsonc
89
89
  {
90
90
  "proxy": {
91
91
  "endpoint": "https://proxy.example.com/v1",
92
- "apiKey": "!cat ~/.config/pi-cliproxyapi/key",
92
+ "apiKey": "!cat ~/.pi/agent/pi-cliproxyapi/key",
93
93
  "providerPrefix": "corp",
94
- "usageKey": "!cat ~/.config/pi-cliproxyapi/usage-key"
94
+ "usageKey": "!cat ~/.pi/agent/pi-cliproxyapi/usage-key"
95
95
  },
96
96
  "builtinProviders": {
97
97
  "anthropic": { "enabled": true, "models": ["claude-opus-4-7"] },
@@ -106,7 +106,7 @@ Then run `/cliproxy-setup` to configure your proxy endpoint.
106
106
  }
107
107
  ```
108
108
 
109
- Values support `!command` (shell exec), `$ENV_VAR`, `~/path` (auto-wrapped to `!cat`), or literal strings.
109
+ Values support `!command` (shell exec), `$ENV_VAR`, or literal strings. The `/cliproxy-setup` wizard also accepts bare `~/path` values and saves them as `!cat` commands; when editing the file by hand, write the `!cat ~/path` form explicitly.
110
110
 
111
111
  ## Discovery
112
112
 
@@ -191,7 +191,7 @@ The sidecar is **optional for basic usage** — without it the plugin falls back
191
191
  ```
192
192
  index.ts ExtensionFactory entry point
193
193
  src/
194
- config.ts ~/.config/pi-cliproxyapi/config.json
194
+ config.ts ~/.pi/agent/pi-cliproxyapi/config.json
195
195
  commands.ts 2 slash commands (hub + setup)
196
196
  apply.ts pi.registerProvider calls
197
197
  fetch-models.ts well-known + /v1/models fallback
package/index.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  * CliProxyAPI endpoint with one corporate key.
4
4
  *
5
5
  * On factory boot we:
6
- * 1. load ~/.config/pi-cliproxyapi/config.json (defaults if missing)
6
+ * 1. load ~/.pi/agent/pi-cliproxyapi/config.json (migrates legacy config; defaults if missing)
7
7
  * 2. fetch discovery (well-known → fall back to /v1/models)
8
8
  * 3. call pi.registerProvider for each enabled built-in + custom provider
9
9
  * 4. register slash commands /cliproxy and /cliproxy-setup
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-cliproxyapi",
3
- "version": "0.3.4",
3
+ "version": "0.3.5",
4
4
  "type": "module",
5
5
  "description": "Pi extension for corporate management of model providers via a single CliProxyAPI endpoint",
6
6
  "license": "MIT",
@@ -25,7 +25,8 @@
25
25
  "cliproxyapi"
26
26
  ],
27
27
  "scripts": {
28
- "typecheck": "tsc --noEmit"
28
+ "typecheck": "tsc --noEmit",
29
+ "check:migration": "node --disable-warning=ExperimentalWarning --experimental-strip-types scripts/check-config-migration.ts"
29
30
  },
30
31
  "peerDependencies": {
31
32
  "@earendil-works/pi-ai": "*",
package/src/config.ts CHANGED
@@ -1,13 +1,13 @@
1
- // ~/.config/pi-cliproxyapi/config.json — load, validate, persist.
1
+ // ~/.pi/agent/pi-cliproxyapi/config.json — migrate, load, validate, persist.
2
2
  //
3
3
  // Schema:
4
4
  //
5
5
  // {
6
6
  // "proxy": {
7
7
  // "endpoint": "https://your-proxy.example.com/v1",
8
- // "apiKey": "!cat ~/.config/pi-cliproxyapi/key",
8
+ // "apiKey": "!cat ~/.pi/agent/pi-cliproxyapi/key",
9
9
  // "providerPrefix": "myproxy",
10
- // "usageKey": "!cat ~/.config/pi-cliproxyapi/usage-key"
10
+ // "usageKey": "!cat ~/.pi/agent/pi-cliproxyapi/usage-key"
11
11
  // },
12
12
  // "builtinProviders": {
13
13
  // "openai": { "enabled": true, "apiOverride": null, "models": ["gpt-5.2"] },
@@ -26,16 +26,71 @@
26
26
  // }
27
27
 
28
28
  import { execSync } from "node:child_process";
29
- import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
29
+ import { randomUUID } from "node:crypto";
30
+ import {
31
+ constants,
32
+ copyFileSync,
33
+ existsSync,
34
+ linkSync,
35
+ mkdirSync,
36
+ readFileSync,
37
+ rmSync,
38
+ unlinkSync,
39
+ writeFileSync,
40
+ } from "node:fs";
30
41
  import { homedir } from "node:os";
31
42
  import { dirname, join } from "node:path";
43
+ import { fileURLToPath } from "node:url";
32
44
 
33
45
  import type { Api } from "@earendil-works/pi-ai";
34
46
 
35
47
  import { log } from "./log.ts";
36
48
 
37
- export const CONFIG_DIR = join(homedir(), ".config", "pi-cliproxyapi");
49
+ export const CONFIG_DIR = join(homedir(), ".pi", "agent", "pi-cliproxyapi");
38
50
  export const CONFIG_PATH = join(CONFIG_DIR, "config.json");
51
+ const LEGACY_CONFIG_PATH = join(
52
+ homedir(),
53
+ ".config",
54
+ "pi-cliproxyapi",
55
+ "config.json",
56
+ );
57
+
58
+ export function isLocalCheckout(): boolean {
59
+ return existsSync(
60
+ join(dirname(fileURLToPath(import.meta.url)), "..", ".git"),
61
+ );
62
+ }
63
+
64
+ export function migrateLegacyConfig(
65
+ legacyPath = LEGACY_CONFIG_PATH,
66
+ configPath = CONFIG_PATH,
67
+ localCheckout = isLocalCheckout(),
68
+ ): void {
69
+ if (existsSync(configPath) || !existsSync(legacyPath)) return;
70
+ let temporaryPath: string | undefined;
71
+ try {
72
+ mkdirSync(dirname(configPath), { recursive: true });
73
+ temporaryPath = `${configPath}.${process.pid}.${randomUUID()}.tmp`;
74
+ copyFileSync(legacyPath, temporaryPath, constants.COPYFILE_EXCL);
75
+ linkSync(temporaryPath, configPath);
76
+ rmSync(temporaryPath);
77
+ temporaryPath = undefined;
78
+ if (!localCheckout) unlinkSync(legacyPath);
79
+ log.info(
80
+ localCheckout ? "legacy config copied to" : "legacy config moved to",
81
+ configPath,
82
+ );
83
+ } catch (err) {
84
+ if (temporaryPath) {
85
+ try {
86
+ rmSync(temporaryPath, { force: true });
87
+ } catch (cleanupErr) {
88
+ log.warn("failed to clean temporary config:", cleanupErr);
89
+ }
90
+ }
91
+ log.warn("failed to migrate legacy config:", err);
92
+ }
93
+ }
39
94
 
40
95
  export interface BuiltinProviderConfig {
41
96
  enabled: boolean;
@@ -92,6 +147,7 @@ const DEFAULT_CONFIG: ProxyConfig = {
92
147
  };
93
148
 
94
149
  export function loadConfig(): ProxyConfig {
150
+ migrateLegacyConfig();
95
151
  if (!existsSync(CONFIG_PATH)) {
96
152
  log.info("config not found, using defaults at", CONFIG_PATH);
97
153
  return structuredClone(DEFAULT_CONFIG);
@@ -115,9 +171,7 @@ function normalizeConfig(raw: unknown): ProxyConfig {
115
171
  if (!raw || typeof raw !== "object") return structuredClone(DEFAULT_CONFIG);
116
172
  const r = raw as Record<string, unknown>;
117
173
  const merged = structuredClone(DEFAULT_CONFIG);
118
- const proxyBlock =
119
- (r.proxy as Record<string, unknown> | undefined) ??
120
- {};
174
+ const proxyBlock = (r.proxy as Record<string, unknown> | undefined) ?? {};
121
175
  merged.proxy.endpoint =
122
176
  typeof proxyBlock.endpoint === "string"
123
177
  ? proxyBlock.endpoint
@@ -21,7 +21,7 @@ import { writeDiscoveryCache } from "./cache.ts";
21
21
  import type { ProxyConfig } from "./config.ts";
22
22
  import { log } from "./log.ts";
23
23
 
24
- export const PLUGIN_USER_AGENT = "pi-cliproxyapi/0.3.3";
24
+ export const PLUGIN_USER_AGENT = "pi-cliproxyapi/0.3.5";
25
25
  const REQUEST_TIMEOUT_MS = 5_000;
26
26
 
27
27
  export interface DiscoveryModelEntry {
@@ -23,7 +23,7 @@ import type { UsageAccount, UsageDocument, UsageGroup } from "./fetch-usage.ts";
23
23
  const GAUGE_ICON = "\u{F0627}";
24
24
 
25
25
  /** Braille fill chars, 8 levels (empty → full). */
26
- const BRAILLE = ["⡀", "⠂", "▌", "⣄", "⣤", "⣶", "⣷", "⣾"];
26
+ const BRAILLE = ["⡀", "⠂", "⣀", "⣄", "⣤", "⣶", "⣷", "⣾"];
27
27
 
28
28
  /**
29
29
  * Map a Pi provider name to the provider key used by the usage API.
package/src/ui-setup.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  // First-run setup wizard: collects endpoint + apiKey + providerPrefix + (optional) usageKey
2
- // and writes them to ~/.config/pi-cliproxyapi/config.json.
2
+ // and writes them to ~/.pi/agent/pi-cliproxyapi/config.json.
3
3
  //
4
4
  // All three fields support the same "!cmd" / "$ENV" / literal semantics as
5
5
  // the rest of the config (see resolveConfigValue). For convenience the wizard