automagik-forge 0.1.9 → 0.1.11

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/bin/cli.js +80 -8
  2. package/package.json +1 -1
package/bin/cli.js CHANGED
@@ -3,6 +3,52 @@
3
3
  const { execSync, spawn } = require("child_process");
4
4
  const path = require("path");
5
5
  const fs = require("fs");
6
+ const zlib = require("zlib");
7
+
8
+ // Fallback ZIP extraction using Node.js when unzip is not available
9
+ function extractZipWithNode(zipPath, extractDir) {
10
+ const buffer = fs.readFileSync(zipPath);
11
+ let offset = 0;
12
+
13
+ // Simple ZIP parser - look for file entries
14
+ while (offset < buffer.length - 30) {
15
+ // Look for local file header signature (0x04034b50)
16
+ if (buffer.readUInt32LE(offset) === 0x04034b50) {
17
+ const filenameLength = buffer.readUInt16LE(offset + 26);
18
+ const extraFieldLength = buffer.readUInt16LE(offset + 28);
19
+ const compressedSize = buffer.readUInt32LE(offset + 18);
20
+ const uncompressedSize = buffer.readUInt32LE(offset + 22);
21
+ const compressionMethod = buffer.readUInt16LE(offset + 8);
22
+
23
+ offset += 30; // Skip local file header
24
+
25
+ const filename = buffer.toString('utf8', offset, offset + filenameLength);
26
+ offset += filenameLength + extraFieldLength;
27
+
28
+ const fileData = buffer.slice(offset, offset + compressedSize);
29
+ offset += compressedSize;
30
+
31
+ // Skip directories
32
+ if (filename.endsWith('/')) continue;
33
+
34
+ const outputPath = path.join(extractDir, filename);
35
+ fs.mkdirSync(path.dirname(outputPath), { recursive: true });
36
+
37
+ if (compressionMethod === 0) {
38
+ // No compression
39
+ fs.writeFileSync(outputPath, fileData);
40
+ } else if (compressionMethod === 8) {
41
+ // Deflate compression
42
+ const decompressed = zlib.inflateRawSync(fileData);
43
+ fs.writeFileSync(outputPath, decompressed);
44
+ } else {
45
+ throw new Error(`Unsupported compression method: ${compressionMethod}`);
46
+ }
47
+ } else {
48
+ offset++;
49
+ }
50
+ }
51
+ }
6
52
 
7
53
  // Load .env file from current working directory
8
54
  function loadEnvFile() {
@@ -105,12 +151,29 @@ function extractAndRun(baseName, launch) {
105
151
  process.exit(1);
106
152
  }
107
153
 
108
- // extract
109
- const unzipCmd =
110
- platform === "win32"
111
- ? `powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`
112
- : `unzip -qq -o "${zipPath}" -d "${extractDir}"`;
113
- execSync(unzipCmd, { stdio: "inherit" });
154
+ // extract with fallback methods
155
+ if (platform === "win32") {
156
+ const unzipCmd = `powershell -Command "Expand-Archive -Path '${zipPath}' -DestinationPath '${extractDir}' -Force"`;
157
+ execSync(unzipCmd, { stdio: "inherit" });
158
+ } else {
159
+ // Try unzip first, fallback to Node.js extraction if not available
160
+ try {
161
+ execSync(`unzip -qq -o "${zipPath}" -d "${extractDir}"`, { stdio: "inherit" });
162
+ } catch (unzipError) {
163
+ console.log("⚠️ unzip not found, using Node.js extraction...");
164
+ try {
165
+ // Fallback to Node.js extraction using yauzl if available, or basic implementation
166
+ extractZipWithNode(zipPath, extractDir);
167
+ } catch (nodeError) {
168
+ console.error("❌ Extraction failed. Please install unzip:");
169
+ console.error(" Ubuntu/Debian: sudo apt-get install unzip");
170
+ console.error(" RHEL/CentOS: sudo yum install unzip");
171
+ console.error(" Alpine: apk add unzip");
172
+ console.error("\nOriginal error:", unzipError.message);
173
+ process.exit(1);
174
+ }
175
+ }
176
+ }
114
177
 
115
178
  // perms & launch
116
179
  if (platform !== "win32") {
@@ -186,7 +249,12 @@ if (isMcpMode || isMcpSseMode) {
186
249
  console.log(`🚀 Starting main backend server on http://${host}:${backendPort}...`);
187
250
  mainServerProc = spawn(mainBin, [], {
188
251
  stdio: ["pipe", "pipe", "pipe"],
189
- env: { ...process.env }
252
+ env: {
253
+ ...process.env,
254
+ BACKEND_PORT: backendPort,
255
+ PORT: backendPort,
256
+ HOST: host
257
+ }
190
258
  });
191
259
 
192
260
  mainServerProc.stdout.on("data", (data) => {
@@ -213,7 +281,11 @@ if (isMcpMode || isMcpSseMode) {
213
281
  console.log(`🚀 Starting MCP SSE server on http://${host}:${mcpSsePort}/sse...`);
214
282
  mcpServerProc = spawn(mcpBin, ["--mcp-sse"], {
215
283
  stdio: ["pipe", "pipe", "pipe"],
216
- env: { ...process.env }
284
+ env: {
285
+ ...process.env,
286
+ MCP_SSE_PORT: mcpSsePort,
287
+ HOST: host
288
+ }
217
289
  });
218
290
 
219
291
  mcpServerProc.stdout.on("data", (data) => {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "automagik-forge",
3
3
  "private": false,
4
- "version": "0.1.9",
4
+ "version": "0.1.11",
5
5
  "main": "index.js",
6
6
  "bin": {
7
7
  "automagik-forge": "bin/cli.js"