@sylphai/adal-cli 0.1.0-beta.101
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.
- package/bin/adal-cli.js +155 -0
- package/lib/platform-resolver.js +50 -0
- package/lib/setup-cache.js +108 -0
- package/package.json +32 -0
package/bin/adal-cli.js
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Main entry point for @sylphai/adal-cli (v2 - with caching)
|
|
5
|
+
* This wrapper uses cached platform package path for better performance
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const { spawn } = require('child_process');
|
|
9
|
+
const path = require('path');
|
|
10
|
+
const fs = require('fs');
|
|
11
|
+
const os = require('os');
|
|
12
|
+
|
|
13
|
+
// Determine current platform
|
|
14
|
+
const platform = os.platform();
|
|
15
|
+
const arch = os.arch();
|
|
16
|
+
|
|
17
|
+
// Map Node.js platform/arch to our package naming
|
|
18
|
+
const platformMap = {
|
|
19
|
+
'darwin-arm64': '@sylphai/adal-cli-darwin-arm64',
|
|
20
|
+
'darwin-x64': '@sylphai/adal-cli-darwin-x64',
|
|
21
|
+
'linux-x64': '@sylphai/adal-cli-linux-x64',
|
|
22
|
+
'linux-arm64': '@sylphai/adal-cli-linux-arm64',
|
|
23
|
+
'win32-x64': '@sylphai/adal-cli-win32-x64',
|
|
24
|
+
'win32-ia32': '@sylphai/adal-cli-win32-x64', // Use x64 for 32-bit Windows too
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const platformKey = `${platform}-${arch}`;
|
|
28
|
+
const packageName = platformMap[platformKey];
|
|
29
|
+
|
|
30
|
+
if (!packageName) {
|
|
31
|
+
console.error(`❌ Unsupported platform: ${platform}-${arch}`);
|
|
32
|
+
console.error('Supported platforms:');
|
|
33
|
+
Object.keys(platformMap).forEach(key => {
|
|
34
|
+
console.error(` - ${key}`);
|
|
35
|
+
});
|
|
36
|
+
process.exit(1);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// Cache file location
|
|
40
|
+
const cacheDir = path.join(__dirname, '..', '.cache');
|
|
41
|
+
const cacheFile = path.join(cacheDir, 'platform-path.json');
|
|
42
|
+
|
|
43
|
+
// Try to load cached path first
|
|
44
|
+
function loadCachedPath() {
|
|
45
|
+
try {
|
|
46
|
+
if (fs.existsSync(cacheFile)) {
|
|
47
|
+
const cache = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
|
48
|
+
// Verify the cached path still exists
|
|
49
|
+
if (cache.path && fs.existsSync(cache.path)) {
|
|
50
|
+
// Check if it's been less than 30 days since last cache
|
|
51
|
+
const cacheAge = Date.now() - cache.timestamp;
|
|
52
|
+
if (cacheAge < 30 * 24 * 60 * 60 * 1000) { // 30 days in milliseconds
|
|
53
|
+
return cache.path;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
} catch (e) {
|
|
58
|
+
// Cache read failed, will find path normally
|
|
59
|
+
}
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// Save path to cache
|
|
64
|
+
function saveCachedPath(platformPath) {
|
|
65
|
+
try {
|
|
66
|
+
if (!fs.existsSync(cacheDir)) {
|
|
67
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
68
|
+
}
|
|
69
|
+
fs.writeFileSync(cacheFile, JSON.stringify({
|
|
70
|
+
path: platformPath,
|
|
71
|
+
platform: platformKey,
|
|
72
|
+
package: packageName,
|
|
73
|
+
timestamp: Date.now()
|
|
74
|
+
}, null, 2));
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// Cache write failed, not critical
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// Find the platform-specific package
|
|
81
|
+
function findPlatformPackage() {
|
|
82
|
+
// Try cached path first
|
|
83
|
+
const cachedPath = loadCachedPath();
|
|
84
|
+
if (cachedPath) {
|
|
85
|
+
// Double-check the cached path still works
|
|
86
|
+
if (fs.existsSync(cachedPath)) {
|
|
87
|
+
return cachedPath;
|
|
88
|
+
}
|
|
89
|
+
// Cached path is stale, will search again and update cache
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// If no cache or cache is stale, search for the package
|
|
93
|
+
const possiblePaths = [
|
|
94
|
+
// When installed globally
|
|
95
|
+
path.join(__dirname, '..', '..', packageName, 'adal-cli.js'),
|
|
96
|
+
// When installed locally in a project
|
|
97
|
+
path.join(process.cwd(), 'node_modules', packageName, 'adal-cli.js'),
|
|
98
|
+
// When running from development
|
|
99
|
+
path.join(__dirname, '..', 'node_modules', packageName, 'adal-cli.js'),
|
|
100
|
+
// Alternative global location
|
|
101
|
+
require.resolve.paths(packageName).map(p => path.join(p, packageName, 'adal-cli.js')).filter(Boolean)
|
|
102
|
+
].flat();
|
|
103
|
+
|
|
104
|
+
for (const testPath of possiblePaths) {
|
|
105
|
+
if (fs.existsSync(testPath)) {
|
|
106
|
+
saveCachedPath(testPath); // Cache the found path
|
|
107
|
+
return testPath;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
// Try using require.resolve as last resort
|
|
112
|
+
try {
|
|
113
|
+
const packagePath = require.resolve(`${packageName}/package.json`);
|
|
114
|
+
const platformBinary = path.join(path.dirname(packagePath), 'adal-cli.js');
|
|
115
|
+
if (fs.existsSync(platformBinary)) {
|
|
116
|
+
saveCachedPath(platformBinary); // Cache the found path
|
|
117
|
+
return platformBinary;
|
|
118
|
+
}
|
|
119
|
+
} catch (e) {
|
|
120
|
+
// Package not found
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
return null;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const platformBinary = findPlatformPackage();
|
|
127
|
+
|
|
128
|
+
if (!platformBinary) {
|
|
129
|
+
console.error(`❌ Platform package ${packageName} not found!`);
|
|
130
|
+
console.error('');
|
|
131
|
+
console.error('The platform-specific package should be installed automatically.');
|
|
132
|
+
console.error('If it\'s not, you can install it manually:');
|
|
133
|
+
console.error(` npm install ${packageName}`);
|
|
134
|
+
console.error('');
|
|
135
|
+
console.error('If you\'re using npm < 7, optional dependencies might not install automatically.');
|
|
136
|
+
console.error('Please upgrade npm or install the platform package manually.');
|
|
137
|
+
process.exit(1);
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Execute the platform-specific binary with all arguments
|
|
141
|
+
const child = spawn(process.execPath, [platformBinary, ...process.argv.slice(2)], {
|
|
142
|
+
stdio: 'inherit',
|
|
143
|
+
env: process.env,
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
// Forward the exit code
|
|
147
|
+
child.on('exit', (code) => {
|
|
148
|
+
process.exit(code || 0);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
// Handle errors
|
|
152
|
+
child.on('error', (error) => {
|
|
153
|
+
console.error(`❌ Failed to execute platform binary: ${error.message}`);
|
|
154
|
+
process.exit(1);
|
|
155
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Platform resolver utilities
|
|
3
|
+
* Can be used programmatically to find the correct platform package
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
const os = require('os');
|
|
7
|
+
const path = require('path');
|
|
8
|
+
const fs = require('fs');
|
|
9
|
+
|
|
10
|
+
const platformMap = {
|
|
11
|
+
'darwin-arm64': '@sylphai/adal-cli-darwin-arm64',
|
|
12
|
+
'darwin-x64': '@sylphai/adal-cli-darwin-x64',
|
|
13
|
+
'linux-x64': '@sylphai/adal-cli-linux-x64',
|
|
14
|
+
'linux-arm64': '@sylphai/adal-cli-linux-arm64',
|
|
15
|
+
'win32-x64': '@sylphai/adal-cli-win32-x64',
|
|
16
|
+
'win32-ia32': '@sylphai/adal-cli-win32-x64',
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
function getCurrentPlatformPackage() {
|
|
20
|
+
const platform = os.platform();
|
|
21
|
+
const arch = os.arch();
|
|
22
|
+
const platformKey = `${platform}-${arch}`;
|
|
23
|
+
return platformMap[platformKey];
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
function isPlatformSupported() {
|
|
27
|
+
return getCurrentPlatformPackage() !== undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function getCachedPath() {
|
|
31
|
+
const cacheFile = path.join(__dirname, '..', '.cache', 'platform-path.json');
|
|
32
|
+
try {
|
|
33
|
+
if (fs.existsSync(cacheFile)) {
|
|
34
|
+
const cache = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
|
|
35
|
+
if (cache.path && fs.existsSync(cache.path)) {
|
|
36
|
+
return cache;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
// Cache read failed
|
|
41
|
+
}
|
|
42
|
+
return null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
module.exports = {
|
|
46
|
+
getCurrentPlatformPackage,
|
|
47
|
+
isPlatformSupported,
|
|
48
|
+
getCachedPath,
|
|
49
|
+
platformMap,
|
|
50
|
+
};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Post-install script to pre-cache the platform package path
|
|
5
|
+
* This runs during npm install to find and cache the platform package location
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
const path = require('path');
|
|
9
|
+
const fs = require('fs');
|
|
10
|
+
const os = require('os');
|
|
11
|
+
|
|
12
|
+
// Determine current platform
|
|
13
|
+
const platform = os.platform();
|
|
14
|
+
const arch = os.arch();
|
|
15
|
+
|
|
16
|
+
const platformMap = {
|
|
17
|
+
'darwin-arm64': '@sylphai/adal-cli-darwin-arm64',
|
|
18
|
+
'darwin-x64': '@sylphai/adal-cli-darwin-x64',
|
|
19
|
+
'linux-x64': '@sylphai/adal-cli-linux-x64',
|
|
20
|
+
'linux-arm64': '@sylphai/adal-cli-linux-arm64',
|
|
21
|
+
'win32-x64': '@sylphai/adal-cli-win32-x64',
|
|
22
|
+
'win32-ia32': '@sylphai/adal-cli-win32-x64',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const platformKey = `${platform}-${arch}`;
|
|
26
|
+
const packageName = platformMap[platformKey];
|
|
27
|
+
|
|
28
|
+
if (!packageName) {
|
|
29
|
+
// Unsupported platform, skip caching
|
|
30
|
+
process.exit(0);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// Cache file location
|
|
34
|
+
const cacheDir = path.join(__dirname, '..', '.cache');
|
|
35
|
+
const cacheFile = path.join(cacheDir, 'platform-path.json');
|
|
36
|
+
|
|
37
|
+
// Find the platform package during installation
|
|
38
|
+
function findAndCachePlatformPackage() {
|
|
39
|
+
const possiblePaths = [
|
|
40
|
+
// When installed globally
|
|
41
|
+
path.join(__dirname, '..', '..', packageName, 'adal-cli.js'),
|
|
42
|
+
// When installed locally in a project
|
|
43
|
+
path.join(process.cwd(), 'node_modules', packageName, 'adal-cli.js'),
|
|
44
|
+
// When running from development
|
|
45
|
+
path.join(__dirname, '..', 'node_modules', packageName, 'adal-cli.js'),
|
|
46
|
+
];
|
|
47
|
+
|
|
48
|
+
// Also check require.resolve paths
|
|
49
|
+
try {
|
|
50
|
+
const resolvePaths = require.resolve.paths(packageName);
|
|
51
|
+
if (resolvePaths) {
|
|
52
|
+
resolvePaths.forEach(p => {
|
|
53
|
+
possiblePaths.push(path.join(p, packageName, 'adal-cli.js'));
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
} catch (e) {
|
|
57
|
+
// Ignore errors
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const testPath of possiblePaths) {
|
|
61
|
+
if (fs.existsSync(testPath)) {
|
|
62
|
+
// Found the platform package, cache it
|
|
63
|
+
try {
|
|
64
|
+
if (!fs.existsSync(cacheDir)) {
|
|
65
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
66
|
+
}
|
|
67
|
+
fs.writeFileSync(cacheFile, JSON.stringify({
|
|
68
|
+
path: testPath,
|
|
69
|
+
platform: platformKey,
|
|
70
|
+
package: packageName,
|
|
71
|
+
timestamp: Date.now(),
|
|
72
|
+
installedAt: new Date().toISOString()
|
|
73
|
+
}, null, 2));
|
|
74
|
+
console.log(`✅ Cached platform package path: ${packageName}`);
|
|
75
|
+
} catch (e) {
|
|
76
|
+
// Cache write failed, not critical
|
|
77
|
+
console.log(`⚠️ Could not cache platform package path: ${e.message}`);
|
|
78
|
+
}
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Try using require.resolve as last resort
|
|
84
|
+
try {
|
|
85
|
+
const packagePath = require.resolve(`${packageName}/package.json`);
|
|
86
|
+
const platformBinary = path.join(path.dirname(packagePath), 'adal-cli.js');
|
|
87
|
+
if (fs.existsSync(platformBinary)) {
|
|
88
|
+
// Cache the found path
|
|
89
|
+
if (!fs.existsSync(cacheDir)) {
|
|
90
|
+
fs.mkdirSync(cacheDir, { recursive: true });
|
|
91
|
+
}
|
|
92
|
+
fs.writeFileSync(cacheFile, JSON.stringify({
|
|
93
|
+
path: platformBinary,
|
|
94
|
+
platform: platformKey,
|
|
95
|
+
package: packageName,
|
|
96
|
+
timestamp: Date.now(),
|
|
97
|
+
installedAt: new Date().toISOString()
|
|
98
|
+
}, null, 2));
|
|
99
|
+
console.log(`✅ Cached platform package path: ${packageName}`);
|
|
100
|
+
}
|
|
101
|
+
} catch (e) {
|
|
102
|
+
// Platform package not found during install, will be found at runtime
|
|
103
|
+
console.log(`⚠️ Platform package ${packageName} not found during install, will detect at runtime`);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
// Run the caching
|
|
108
|
+
findAndCachePlatformPackage();
|
package/package.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@sylphai/adal-cli",
|
|
3
|
+
"version": "0.1.0-beta.101",
|
|
4
|
+
"description": "AI-powered CLI for development and research tasks",
|
|
5
|
+
"bin": {
|
|
6
|
+
"adal": "bin/adal-cli.js"
|
|
7
|
+
},
|
|
8
|
+
"scripts": {
|
|
9
|
+
"postinstall": "node lib/setup-cache.js"
|
|
10
|
+
},
|
|
11
|
+
"optionalDependencies": {
|
|
12
|
+
"@sylphai/adal-cli-darwin-arm64": "0.1.0-beta.101",
|
|
13
|
+
"@sylphai/adal-cli-darwin-x64": "0.1.0-beta.101",
|
|
14
|
+
"@sylphai/adal-cli-linux-x64": "0.1.0-beta.101",
|
|
15
|
+
"@sylphai/adal-cli-linux-arm64": "0.1.0-beta.101",
|
|
16
|
+
"@sylphai/adal-cli-win32-x64": "0.1.0-beta.101"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"bin/",
|
|
20
|
+
"lib/"
|
|
21
|
+
],
|
|
22
|
+
"keywords": ["ai", "cli", "development", "research", "assistant"],
|
|
23
|
+
"author": "SylphAI",
|
|
24
|
+
"license": "SylphAI Proprietary",
|
|
25
|
+
"repository": {
|
|
26
|
+
"type": "git",
|
|
27
|
+
"url": "https://github.com/SylphAI-Inc/adal-cli.git"
|
|
28
|
+
},
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=14.0.0"
|
|
31
|
+
}
|
|
32
|
+
}
|