ai-rulez 5.12.0 → 5.12.2

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.
Files changed (2) hide show
  1. package/install.js +61 -1
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -2,6 +2,7 @@ const fs = require("node:fs");
2
2
  const path = require("node:path");
3
3
  const https = require("node:https");
4
4
  const http = require("node:http");
5
+ const tls = require("node:tls");
5
6
  const crypto = require("node:crypto");
6
7
  const { exec, spawn } = require("node:child_process");
7
8
  const { promisify } = require("node:util");
@@ -135,12 +136,69 @@ function usePackagedBinaryIfAvailable(os, arch, binaryName, binDir) {
135
136
  return false;
136
137
  }
137
138
 
139
+ function proxyFor(targetUrl, env = process.env) {
140
+ const target = new URL(targetUrl);
141
+ const raw =
142
+ target.protocol === "https:"
143
+ ? env.HTTPS_PROXY || env.https_proxy || env.ALL_PROXY || env.all_proxy
144
+ : env.HTTP_PROXY || env.http_proxy || env.ALL_PROXY || env.all_proxy;
145
+ if (!raw) return null;
146
+
147
+ const noProxy = (env.NO_PROXY || env.no_proxy || "").split(",").map((e) => e.trim().toLowerCase());
148
+ const host = target.hostname.toLowerCase();
149
+ for (const entry of noProxy) {
150
+ if (!entry) continue;
151
+ if (entry === "*") return null;
152
+ const suffix = entry.replace(/^\*?\./, "");
153
+ if (host === suffix || host.endsWith(`.${suffix}`)) return null;
154
+ }
155
+
156
+ const proxy = new URL(raw.includes("://") ? raw : `http://${raw}`);
157
+ return proxy.protocol === "http:" ? proxy : null;
158
+ }
159
+
160
+ // Node's https module ignores HTTPS_PROXY, so sandboxes that only allow egress
161
+ // through a proxy (Codex, corporate networks) see ECONNREFUSED. Tunnel with CONNECT.
162
+ function createProxyAgent(proxy) {
163
+ const agent = new https.Agent();
164
+ agent.createConnection = (options, callback) => {
165
+ const port = options.port || 443;
166
+ const headers = { Host: `${options.host}:${port}` };
167
+ if (proxy.username) {
168
+ const credentials = `${decodeURIComponent(proxy.username)}:${decodeURIComponent(proxy.password)}`;
169
+ headers["Proxy-Authorization"] = `Basic ${Buffer.from(credentials).toString("base64")}`;
170
+ }
171
+ const connectRequest = http.request({
172
+ host: proxy.hostname,
173
+ port: proxy.port || 80,
174
+ method: "CONNECT",
175
+ path: `${options.host}:${port}`,
176
+ headers,
177
+ });
178
+ connectRequest.once("connect", (res, socket) => {
179
+ if (res.statusCode !== 200) {
180
+ socket.destroy();
181
+ callback(new Error(`Proxy CONNECT to ${options.host}:${port} failed: HTTP ${res.statusCode}`));
182
+ return;
183
+ }
184
+ callback(null, tls.connect({ socket, servername: options.servername || options.host }));
185
+ });
186
+ connectRequest.once("error", callback);
187
+ connectRequest.end();
188
+ };
189
+ return agent;
190
+ }
191
+
138
192
  async function downloadBinary(url, dest, retryCount = 0) {
139
193
  return new Promise((resolve, reject) => {
140
194
  const file = fs.createWriteStream(dest);
141
195
  const protocol = url.startsWith("https") ? https : http;
142
196
 
143
- const request = protocol.get(url, { timeout: DOWNLOAD_TIMEOUT }, (response) => {
197
+ const proxy = protocol === https ? proxyFor(url) : null;
198
+ const requestOptions = { timeout: DOWNLOAD_TIMEOUT };
199
+ if (proxy) requestOptions.agent = createProxyAgent(proxy);
200
+
201
+ const request = protocol.get(url, requestOptions, (response) => {
144
202
  if (response.statusCode === 302 || response.statusCode === 301) {
145
203
  file.close();
146
204
  try {
@@ -466,6 +524,8 @@ if (typeof module !== "undefined" && module.exports) {
466
524
  getPackagedBinaryCandidates,
467
525
  usePackagedBinaryIfAvailable,
468
526
  downloadBinary,
527
+ proxyFor,
528
+ createProxyAgent,
469
529
  extractArchive,
470
530
  calculateSHA256,
471
531
  getExpectedChecksum,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ai-rulez",
3
- "version": "5.12.0",
3
+ "version": "5.12.2",
4
4
  "description": "Author, generate, validate and govern rules, skills, plugins and MCP configuration for 52 AI coding assistants from one .ai-rulez/ source. Lock, sign and SBOM your agent configuration, review it with verified model evidence, and publish plugin bundles. CLI, MCP server and Go API.",
5
5
  "keywords": [
6
6
  "ai-rules",