@gajae-code/ai 0.18.12 → 0.19.0

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.
@@ -1,5 +1,7 @@
1
1
  import * as net from "node:net";
2
2
  import * as tls from "node:tls";
3
+ import { loadedProjectEnvSnapshot } from "@gajae-code/utils";
4
+ import { canonicalEnvKey } from "@gajae-code/utils/env-file";
3
5
 
4
6
  export interface ProxyConnectOptions {
5
7
  signal?: AbortSignal;
@@ -48,6 +50,33 @@ function firstEnvValue(...names: string[]): string | undefined {
48
50
  return undefined;
49
51
  }
50
52
 
53
+ // This module may load lazily after --worktree changes cwd. Use the shared
54
+ // process-startup snapshot captured by @gajae-code/utils before that transition.
55
+ // A dynamic declaration is refused, and a runtime value equal to the declared
56
+ // text is ambiguous. A distinct shell value remains a selector.
57
+ const projectProxyEnv = loadedProjectEnvSnapshot();
58
+
59
+ function projectSuppliedProxy(name: string, runtime: string): boolean {
60
+ const key = canonicalEnvKey(name);
61
+ const declared = projectProxyEnv.values[key];
62
+ if (declared === undefined && !projectProxyEnv.dynamic.has(key)) return false;
63
+ return projectProxyEnv.dynamic.has(key) || declared === runtime || declared === runtime.trim();
64
+ }
65
+
66
+ function trustedProxyEnvValue(name: string): string | undefined {
67
+ const runtime = process.env[name];
68
+ if (!runtime?.trim() || projectSuppliedProxy(name, runtime)) return undefined;
69
+ return runtime.trim();
70
+ }
71
+
72
+ function firstTrustedProxyEnv(...names: string[]): string | undefined {
73
+ for (const name of names) {
74
+ const value = trustedProxyEnvValue(name);
75
+ if (value) return value;
76
+ }
77
+ return undefined;
78
+ }
79
+
51
80
  function normalizeHost(hostname: string): string {
52
81
  return hostname
53
82
  .trim()
@@ -254,18 +283,18 @@ export function getProxyForUrl(provider: string, url: URL): string | undefined {
254
283
  const normalizedProvider = normalizeProvider(provider);
255
284
  const protocolProxy =
256
285
  url.protocol === "https:"
257
- ? firstEnvValue("HTTPS_PROXY", "https_proxy")
286
+ ? firstTrustedProxyEnv("HTTPS_PROXY", "https_proxy")
258
287
  : url.protocol === "http:"
259
- ? firstEnvValue("HTTP_PROXY", "http_proxy")
288
+ ? firstTrustedProxyEnv("HTTP_PROXY", "http_proxy")
260
289
  : undefined;
261
290
  const candidates = [
262
- normalizedProvider ? process.env[`PI_PROXY_${normalizedProvider}`] : undefined,
263
- process.env.PI_PROXY,
291
+ normalizedProvider ? trustedProxyEnvValue(`PI_PROXY_${normalizedProvider}`) : undefined,
292
+ trustedProxyEnvValue("PI_PROXY"),
264
293
  protocolProxy,
265
- firstEnvValue("ALL_PROXY", "all_proxy"),
294
+ firstTrustedProxyEnv("ALL_PROXY", "all_proxy"),
266
295
  ];
267
296
  for (const candidate of candidates) {
268
- if (candidate?.trim()) return candidate.trim();
297
+ if (candidate) return candidate;
269
298
  }
270
299
  return undefined;
271
300
  }