snow-flow 9.0.3 → 9.0.6

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.
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env node
2
+ const { spawn } = require('child_process');
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const os = require('os');
6
+
7
+ const platform = os.platform() === 'win32' ? 'windows' : os.platform();
8
+ const arch = os.arch() === 'arm64' ? 'arm64' : 'x64';
9
+
10
+ const binaryName = platform === 'windows' ? 'snow-code.exe' : 'snow-code';
11
+ const packageDir = path.dirname(__dirname);
12
+ const binaryPath = path.join(packageDir, 'bin', binaryName);
13
+
14
+ if (!fs.existsSync(binaryPath)) {
15
+ console.error('Error: snow-flow binary not found.');
16
+ console.error('');
17
+ console.error('The binary should have been downloaded during installation.');
18
+ console.error('Try reinstalling: npm install -g snow-flow');
19
+ console.error('');
20
+ console.error(`Expected binary at: ${binaryPath}`);
21
+ process.exit(1);
22
+ }
23
+
24
+ // Execute the binary
25
+ const child = spawn(binaryPath, process.argv.slice(2), {
26
+ stdio: 'inherit',
27
+ env: process.env
28
+ });
29
+
30
+ child.on('exit', (code) => {
31
+ process.exit(code || 0);
32
+ });
33
+
34
+ child.on('error', (err) => {
35
+ console.error(`Failed to start snow-flow: ${err.message}`);
36
+ process.exit(1);
37
+ });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "$schema": "https://json.schemastore.org/package.json",
3
- "version": "9.0.3",
3
+ "version": "9.0.6",
4
4
  "name": "snow-flow",
5
5
  "description": "Snow-Flow - AI-powered ServiceNow development CLI with 410+ MCP tools",
6
6
  "type": "module",
@@ -33,9 +33,9 @@
33
33
  "release:major": "npm version major -m 'chore: Bump version to %s' && git push --no-verify && git push --tags --no-verify"
34
34
  },
35
35
  "bin": {
36
- "snow-flow": "./bin/snow-code.js",
37
- "snow-code": "./bin/snow-code.js",
38
- "snowcode": "./bin/snow-code.js"
36
+ "snow-flow": "./bin/snow-code.cjs",
37
+ "snow-code": "./bin/snow-code.cjs",
38
+ "snowcode": "./bin/snow-code.cjs"
39
39
  },
40
40
  "exports": {
41
41
  "./*": "./src/*.ts"
@@ -101,12 +101,5 @@
101
101
  "zod": "3.25.76",
102
102
  "zod-to-json-schema": "3.24.5",
103
103
  "tsx": "4.20.6"
104
- },
105
- "optionalDependencies": {
106
- "snow-flow-darwin-arm64": "*",
107
- "snow-flow-darwin-x64": "*",
108
- "snow-flow-linux-arm64": "*",
109
- "snow-flow-linux-x64": "*",
110
- "snow-flow-windows-x64": "*"
111
104
  }
112
105
  }
package/postinstall.cjs CHANGED
@@ -2,38 +2,109 @@
2
2
  const fs = require('fs');
3
3
  const path = require('path');
4
4
  const os = require('os');
5
+ const https = require('https');
6
+ const { execSync } = require('child_process');
7
+ const zlib = require('zlib');
5
8
 
6
- // Make platform binary executable after install
7
- try {
8
- const platform = os.platform();
9
- const arch = os.arch();
10
-
11
- // Skip Windows
12
- if (platform === 'win32') {
13
- process.exit(0);
9
+ const platform = os.platform() === 'win32' ? 'windows' : os.platform();
10
+ const arch = os.arch() === 'arm64' ? 'arm64' : 'x64';
11
+
12
+ const binaryName = platform === 'windows' ? 'snow-code.exe' : 'snow-code';
13
+ const packageDir = __dirname;
14
+ const binDir = path.join(packageDir, 'bin');
15
+ const binaryPath = path.join(binDir, binaryName);
16
+
17
+ // Get version from package.json
18
+ function getVersion() {
19
+ try {
20
+ const pkg = JSON.parse(fs.readFileSync(path.join(packageDir, 'package.json'), 'utf8'));
21
+ return pkg.version;
22
+ } catch {
23
+ return null;
14
24
  }
15
-
16
- // Map Node.js arch to our naming
17
- const archMap = {
18
- 'arm64': 'arm64',
19
- 'x64': 'x64'
20
- };
21
-
22
- const mappedArch = archMap[arch];
23
- if (!mappedArch) {
24
- console.log(`Unknown architecture: ${arch}`);
25
- process.exit(0);
25
+ }
26
+
27
+ // Follow redirects and download file
28
+ function download(url) {
29
+ return new Promise((resolve, reject) => {
30
+ const request = https.get(url, { headers: { 'User-Agent': 'snow-flow-installer' } }, (response) => {
31
+ if (response.statusCode === 302 || response.statusCode === 301) {
32
+ download(response.headers.location).then(resolve).catch(reject);
33
+ return;
34
+ }
35
+ if (response.statusCode !== 200) {
36
+ reject(new Error(`Failed to download: HTTP ${response.statusCode}`));
37
+ return;
38
+ }
39
+
40
+ const chunks = [];
41
+ response.on('data', chunk => chunks.push(chunk));
42
+ response.on('end', () => resolve(Buffer.concat(chunks)));
43
+ response.on('error', reject);
44
+ });
45
+ request.on('error', reject);
46
+ });
47
+ }
48
+
49
+ async function downloadBinary() {
50
+ const version = getVersion();
51
+ if (!version) {
52
+ console.log('Could not determine version, skipping binary download');
53
+ return false;
26
54
  }
27
-
28
- // Find binary in node_modules
29
- const binaryPackage = `@groeimetai/snow-flow-${platform}-${mappedArch}`;
30
- const binaryPath = path.join(__dirname, 'node_modules', binaryPackage, 'bin', 'snow-code');
31
-
32
- if (fs.existsSync(binaryPath)) {
33
- fs.chmodSync(binaryPath, 0o755);
34
- console.log(`✅ Made ${binaryPackage} executable`);
55
+
56
+ const assetName = `snow-flow-${platform}-${arch}`;
57
+ const tarballName = `${assetName}.tar.gz`;
58
+ const releaseUrl = `https://github.com/groeimetai/snow-flow/releases/download/v${version}/${tarballName}`;
59
+
60
+ console.log(`Downloading snow-flow binary for ${platform}-${arch}...`);
61
+ console.log(`URL: ${releaseUrl}`);
62
+
63
+ try {
64
+ // Download the tarball
65
+ const tarballData = await download(releaseUrl);
66
+
67
+ // Create temp file
68
+ const tmpDir = os.tmpdir();
69
+ const tarballPath = path.join(tmpDir, tarballName);
70
+ fs.writeFileSync(tarballPath, tarballData);
71
+
72
+ // Ensure bin directory exists
73
+ if (!fs.existsSync(binDir)) {
74
+ fs.mkdirSync(binDir, { recursive: true });
75
+ }
76
+
77
+ // Extract using tar command
78
+ console.log('Extracting binary...');
79
+ execSync(`tar -xzf "${tarballPath}" -C "${binDir}" --strip-components=1`, { stdio: 'pipe' });
80
+
81
+ // Clean up
82
+ fs.unlinkSync(tarballPath);
83
+
84
+ // Make executable on non-Windows
85
+ if (platform !== 'windows' && fs.existsSync(binaryPath)) {
86
+ fs.chmodSync(binaryPath, 0o755);
87
+ }
88
+
89
+ console.log('✅ Binary installed successfully!');
90
+ return true;
91
+ } catch (error) {
92
+ console.log(`Note: Could not download pre-built binary (${error.message})`);
93
+ console.log('You may need to build from source or check your network connection.');
94
+ return false;
95
+ }
96
+ }
97
+
98
+ // Only run if binary doesn't exist
99
+ if (!fs.existsSync(binaryPath)) {
100
+ downloadBinary().catch(err => {
101
+ console.log(`Download failed: ${err.message}`);
102
+ });
103
+ } else {
104
+ // Make sure it's executable
105
+ if (platform !== 'windows') {
106
+ try {
107
+ fs.chmodSync(binaryPath, 0o755);
108
+ } catch {}
35
109
  }
36
- } catch (error) {
37
- // Silently fail - not critical
38
- console.log('Note: Could not set binary permissions (non-critical)');
39
110
  }
package/bin/snow-code.js DELETED
@@ -1,67 +0,0 @@
1
- #!/usr/bin/env node
2
- const { execSync, spawn } = require('child_process');
3
- const fs = require('fs');
4
- const path = require('path');
5
- const os = require('os');
6
-
7
- const platform = os.platform() === 'win32' ? 'windows' : os.platform();
8
- const arch = os.arch();
9
-
10
- // Map architecture names
11
- const archMap = {
12
- 'arm64': 'arm64',
13
- 'x64': 'x64',
14
- 'x86_64': 'x64'
15
- };
16
-
17
- const mappedArch = archMap[arch] || 'x64';
18
- const packageName = `snow-flow-${platform}-${mappedArch}`;
19
-
20
- // Search for binary in node_modules
21
- function findBinary() {
22
- let dir = __dirname;
23
-
24
- // Walk up looking for node_modules
25
- while (dir !== path.dirname(dir)) {
26
- // Check in sibling node_modules (for global install)
27
- const globalPath = path.join(path.dirname(dir), 'node_modules', packageName, 'bin', platform === 'windows' ? 'snow-code.exe' : 'snow-code');
28
- if (fs.existsSync(globalPath)) {
29
- return globalPath;
30
- }
31
-
32
- // Check in parent's node_modules
33
- const localPath = path.join(dir, 'node_modules', packageName, 'bin', platform === 'windows' ? 'snow-code.exe' : 'snow-code');
34
- if (fs.existsSync(localPath)) {
35
- return localPath;
36
- }
37
-
38
- dir = path.dirname(dir);
39
- }
40
-
41
- return null;
42
- }
43
-
44
- const binaryPath = findBinary();
45
-
46
- if (!binaryPath) {
47
- console.error(`Error: Could not find snow-flow binary for ${platform}-${mappedArch}`);
48
- console.error(`Expected package: ${packageName}`);
49
- console.error('');
50
- console.error('Try reinstalling: npm install -g snow-flow');
51
- process.exit(1);
52
- }
53
-
54
- // Execute the binary
55
- const child = spawn(binaryPath, process.argv.slice(2), {
56
- stdio: 'inherit',
57
- env: process.env
58
- });
59
-
60
- child.on('exit', (code) => {
61
- process.exit(code || 0);
62
- });
63
-
64
- child.on('error', (err) => {
65
- console.error(`Failed to start snow-flow: ${err.message}`);
66
- process.exit(1);
67
- });
package/bin/snow-flow.cmd DELETED
@@ -1,58 +0,0 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
-
4
- if defined OPENCODE_BIN_PATH (
5
- set "resolved=%OPENCODE_BIN_PATH%"
6
- goto :execute
7
- )
8
-
9
- rem Get the directory of this script
10
- set "script_dir=%~dp0"
11
- set "script_dir=%script_dir:~0,-1%"
12
-
13
- rem Detect platform and architecture
14
- set "platform=windows"
15
-
16
- rem Detect architecture
17
- if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
18
- set "arch=x64"
19
- ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
20
- set "arch=arm64"
21
- ) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
22
- set "arch=x86"
23
- ) else (
24
- set "arch=x64"
25
- )
26
-
27
- set "name=opencode-!platform!-!arch!"
28
- set "binary=opencode.exe"
29
-
30
- rem Search for the binary starting from script location
31
- set "resolved="
32
- set "current_dir=%script_dir%"
33
-
34
- :search_loop
35
- set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
36
- if exist "%candidate%" (
37
- set "resolved=%candidate%"
38
- goto :execute
39
- )
40
-
41
- rem Move up one directory
42
- for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
43
- set "parent_dir=%parent_dir:~0,-1%"
44
-
45
- rem Check if we've reached the root
46
- if "%current_dir%"=="%parent_dir%" goto :not_found
47
- set "current_dir=%parent_dir%"
48
- goto :search_loop
49
-
50
- :not_found
51
- echo It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "%name%" package >&2
52
- exit /b 1
53
-
54
- :execute
55
- rem Execute the binary with all arguments in the same console window
56
- rem Use start /b /wait to ensure it runs in the current shell context for all shells
57
- start /b /wait "" "%resolved%" %*
58
- exit /b %ERRORLEVEL%
package/bin/snowcode.cmd DELETED
@@ -1,58 +0,0 @@
1
- @echo off
2
- setlocal enabledelayedexpansion
3
-
4
- if defined OPENCODE_BIN_PATH (
5
- set "resolved=%OPENCODE_BIN_PATH%"
6
- goto :execute
7
- )
8
-
9
- rem Get the directory of this script
10
- set "script_dir=%~dp0"
11
- set "script_dir=%script_dir:~0,-1%"
12
-
13
- rem Detect platform and architecture
14
- set "platform=windows"
15
-
16
- rem Detect architecture
17
- if "%PROCESSOR_ARCHITECTURE%"=="AMD64" (
18
- set "arch=x64"
19
- ) else if "%PROCESSOR_ARCHITECTURE%"=="ARM64" (
20
- set "arch=arm64"
21
- ) else if "%PROCESSOR_ARCHITECTURE%"=="x86" (
22
- set "arch=x86"
23
- ) else (
24
- set "arch=x64"
25
- )
26
-
27
- set "name=opencode-!platform!-!arch!"
28
- set "binary=opencode.exe"
29
-
30
- rem Search for the binary starting from script location
31
- set "resolved="
32
- set "current_dir=%script_dir%"
33
-
34
- :search_loop
35
- set "candidate=%current_dir%\node_modules\%name%\bin\%binary%"
36
- if exist "%candidate%" (
37
- set "resolved=%candidate%"
38
- goto :execute
39
- )
40
-
41
- rem Move up one directory
42
- for %%i in ("%current_dir%") do set "parent_dir=%%~dpi"
43
- set "parent_dir=%parent_dir:~0,-1%"
44
-
45
- rem Check if we've reached the root
46
- if "%current_dir%"=="%parent_dir%" goto :not_found
47
- set "current_dir=%parent_dir%"
48
- goto :search_loop
49
-
50
- :not_found
51
- echo It seems that your package manager failed to install the right version of the opencode CLI for your platform. You can try manually installing the "%name%" package >&2
52
- exit /b 1
53
-
54
- :execute
55
- rem Execute the binary with all arguments in the same console window
56
- rem Use start /b /wait to ensure it runs in the current shell context for all shells
57
- start /b /wait "" "%resolved%" %*
58
- exit /b %ERRORLEVEL%