@cc-claw/peri 0.1.8 → 0.2.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.
Files changed (2) hide show
  1. package/install.js +68 -15
  2. package/package.json +1 -1
package/install.js CHANGED
@@ -1,8 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
 
3
- const { createWriteStream, mkdirSync, chmodSync, existsSync } = require("fs");
3
+ const { createWriteStream, mkdirSync, chmodSync, existsSync, renameSync, unlinkSync, writeFileSync } = require("fs");
4
4
  const { join } = require("path");
5
- const { get } = require("https");
6
5
  const { execSync } = require("child_process");
7
6
 
8
7
  const VERSION = require("./package.json").version;
@@ -18,20 +17,36 @@ const PLATFORMS = {
18
17
  };
19
18
 
20
19
  function getPlatformKey() {
21
- const os = process.platform;
22
- const arch = process.arch;
23
- const key = `${os}-${arch}`;
20
+ const key = `${process.platform}-${process.arch}`;
24
21
  if (!PLATFORMS[key]) {
25
- throw new Error(`Unsupported platform: ${os}-${arch}. Supported: ${Object.keys(PLATFORMS).join(", ")}`);
22
+ throw new Error(`Unsupported platform: ${key}. Supported: ${Object.keys(PLATFORMS).join(", ")}`);
26
23
  }
27
24
  return key;
28
25
  }
29
26
 
27
+ function getProxyUrl() {
28
+ // Check common proxy environment variables
29
+ const proxy = process.env.HTTPS_PROXY || process.env.https_proxy
30
+ || process.env.HTTP_PROXY || process.env.http_proxy
31
+ || process.env.ALL_PROXY || process.env.all_proxy;
32
+ return proxy || null;
33
+ }
34
+
30
35
  function download(url) {
36
+ const proxyUrl = getProxyUrl();
37
+
38
+ if (proxyUrl) {
39
+ return downloadViaProxy(url, proxyUrl);
40
+ }
41
+ return downloadDirect(url);
42
+ }
43
+
44
+ function downloadDirect(url) {
45
+ const { get } = require("https");
31
46
  return new Promise((resolve, reject) => {
32
47
  get(url, (res) => {
33
48
  if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
34
- download(res.headers.location).then(resolve, reject);
49
+ downloadDirect(res.headers.location).then(resolve, reject);
35
50
  return;
36
51
  }
37
52
  if (res.statusCode !== 200) {
@@ -46,8 +61,51 @@ function download(url) {
46
61
  });
47
62
  }
48
63
 
64
+ function downloadViaProxy(url, proxyUrl) {
65
+ const { URL } = require("url");
66
+ const target = new URL(url);
67
+ const proxy = new URL(proxyUrl);
68
+
69
+ const isHttps = proxy.protocol === "https:" || proxy.protocol === "https:";
70
+ const proxyModule = isHttps ? require("https") : require("http");
71
+
72
+ const proxyOpts = {
73
+ hostname: proxy.hostname,
74
+ port: proxy.port || (isHttps ? 443 : 80),
75
+ path: url,
76
+ method: "GET",
77
+ headers: { "Host": target.hostname, "User-Agent": "peri-installer" },
78
+ };
79
+
80
+ // Support proxy auth
81
+ if (proxy.username) {
82
+ const auth = decodeURIComponent(`${proxy.username}:${proxy.password || ""}`);
83
+ proxyOpts.headers["Proxy-Authorization"] = `Basic ${Buffer.from(auth).toString("base64")}`;
84
+ }
85
+
86
+ console.log(` Using proxy: ${proxy.hostname}:${proxy.port || (isHttps ? 443 : 80)}`);
87
+
88
+ return new Promise((resolve, reject) => {
89
+ const req = proxyModule.request(proxyOpts, (res) => {
90
+ if (res.statusCode >= 300 && res.statusCode < 400 && res.headers.location) {
91
+ download(res.headers.location).then(resolve, reject);
92
+ return;
93
+ }
94
+ if (res.statusCode !== 200) {
95
+ reject(new Error(`Download failed: HTTP ${res.statusCode} for ${url}`));
96
+ return;
97
+ }
98
+ const chunks = [];
99
+ res.on("data", (chunk) => chunks.push(chunk));
100
+ res.on("end", () => resolve(Buffer.concat(chunks)));
101
+ res.on("error", reject);
102
+ });
103
+ req.on("error", reject);
104
+ req.end();
105
+ });
106
+ }
107
+
49
108
  function extractTarGz(buffer, dest) {
50
- const { writeFileSync, unlinkSync } = require("fs");
51
109
  const tmpFile = join(dest, "peri.tar.gz");
52
110
  writeFileSync(tmpFile, buffer);
53
111
  execSync(`tar -xzf "${tmpFile}" -C "${dest}"`, { stdio: "ignore" });
@@ -55,7 +113,6 @@ function extractTarGz(buffer, dest) {
55
113
  }
56
114
 
57
115
  function extractZip(buffer, dest) {
58
- const { writeFileSync } = require("fs");
59
116
  const AdmZip = require("adm-zip");
60
117
  const zip = new AdmZip(buffer);
61
118
  zip.extractAllTo(dest, true);
@@ -83,8 +140,6 @@ async function main() {
83
140
  extractZip(buffer, binDir);
84
141
  }
85
142
 
86
- // Rename extracted binary to a fixed name so bin/peri wrapper can find it
87
- const { renameSync, unlinkSync } = require("fs");
88
143
  const extractedName = platform.os === "win32"
89
144
  ? `peri-${platform.suffix}.exe`
90
145
  : `peri-${platform.suffix}`;
@@ -98,11 +153,9 @@ async function main() {
98
153
  }
99
154
 
100
155
  if (platform.os !== "win32") {
101
- const { chmodSync: chmod } = require("fs");
102
- chmod(finalPath, 0o755);
103
- // Ensure the shell wrapper is also executable
156
+ chmodSync(finalPath, 0o755);
104
157
  const wrapperPath = join(__dirname, "bin", "peri");
105
- if (existsSync(wrapperPath)) chmod(wrapperPath, 0o755);
158
+ if (existsSync(wrapperPath)) chmodSync(wrapperPath, 0o755);
106
159
  }
107
160
 
108
161
  console.log(`peri ${VERSION} installed successfully.`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cc-claw/peri",
3
- "version": "0.1.8",
3
+ "version": "0.2.0",
4
4
  "description": "Terminal coding agent powered by open-source models — Rust-built, Claude Code compatible",
5
5
  "keywords": [
6
6
  "agent",