@the-17/agentsecrets 1.1.4 → 1.1.5

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.
@@ -1,166 +1,152 @@
1
- #!/usr/bin/env node
2
-
3
- const os = require('os');
4
- const fs = require('fs');
5
- const path = require('path');
6
- const { spawn } = require('child_process');
7
- const https = require('https');
8
- const tar = require('tar');
9
-
10
- const GITHUB_REPO = "The-17/agentsecrets";
11
-
12
- function getPlatformInfo() {
13
- const platform = os.platform();
14
- const arch = os.arch();
15
-
16
- let osName = platform;
17
- if (platform === 'win32') osName = 'windows';
18
- if (platform === 'darwin') osName = 'darwin';
19
- if (platform === 'linux') osName = 'linux';
20
-
21
- let archName = 'amd64';
22
- if (arch === 'x64') archName = 'amd64';
23
- if (arch === 'arm64') archName = 'arm64';
24
- if (arch === 'ia32') archName = '386';
25
-
26
- return { osName, archName };
27
- }
28
-
29
- function httpsGet(url) {
30
- return new Promise((resolve, reject) => {
31
- https.get(url, { headers: { 'User-Agent': 'agentsecrets-npm' } }, (res) => {
32
- if (res.statusCode === 301 || res.statusCode === 302) {
33
- return httpsGet(res.headers.location).then(resolve).catch(reject);
34
- }
35
- let data = '';
36
- res.on('data', chunk => data += chunk);
37
- res.on('end', () => resolve({ statusCode: res.statusCode, body: data }));
38
- }).on('error', reject);
39
- });
40
- }
41
-
42
- const CACHE_TTL_MS = 7 * 24 * 60 * 60 * 1000; // 7 days
43
-
44
- async function getLatestVersion(baseDir) {
45
- const cacheFile = path.join(baseDir, 'version.cache');
46
-
47
- // Check cache first
48
- if (fs.existsSync(cacheFile)) {
49
- const cache = JSON.parse(fs.readFileSync(cacheFile, 'utf8'));
50
- if (Date.now() - cache.timestamp < CACHE_TTL_MS) {
51
- return cache.version;
52
- }
53
- }
54
-
55
- try {
56
- const { body } = await httpsGet(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`);
57
- const release = JSON.parse(body);
58
- const version = release.tag_name.replace(/^v/, '');
59
-
60
- // Save to cache
61
- fs.writeFileSync(cacheFile, JSON.stringify({ version, timestamp: Date.now() }));
62
- return version;
63
- } catch {
64
- return null;
65
- }
66
- }
67
-
68
- async function downloadFile(url, dest) {
69
- return new Promise((resolve, reject) => {
70
- const file = fs.createWriteStream(dest);
71
- https.get(url, { headers: { 'User-Agent': 'agentsecrets-npm' } }, (response) => {
72
- if (response.statusCode === 302 || response.statusCode === 301) {
73
- downloadFile(response.headers.location, dest).then(resolve).catch(reject);
74
- return;
75
- }
76
- if (response.statusCode !== 200) {
77
- reject(new Error(`Failed to download: ${response.statusCode}`));
78
- return;
79
- }
80
- response.pipe(file);
81
- file.on('finish', () => file.close(resolve));
82
- }).on('error', (err) => {
83
- fs.unlink(dest, () => reject(err));
84
- });
85
- });
86
- }
87
-
88
- async function ensureBinary() {
89
- const { osName, archName } = getPlatformInfo();
90
- const baseDir = path.join(os.homedir(), '.agentsecrets', 'bin');
91
- if (!fs.existsSync(baseDir)) {
92
- fs.mkdirSync(baseDir, { recursive: true });
93
- }
94
-
95
- let binaryName = 'agentsecrets';
96
- if (osName === 'windows') binaryName += '.exe';
97
-
98
- // Check GitHub for the latest version
99
- const latestVersion = await getLatestVersion(baseDir);
100
-
101
- if (!latestVersion) {
102
- // Offline or GitHub unreachable — fall back to any existing binary
103
- const existing = fs.readdirSync(baseDir).find(f => f.startsWith(binaryName));
104
- if (existing) {
105
- process.stderr.write('Could not reach GitHub. Using cached binary.\n');
106
- return path.join(baseDir, existing);
107
- }
108
- throw new Error('No cached binary and could not reach GitHub to download one.');
109
- }
110
-
111
- const binaryPath = path.join(baseDir, `${binaryName}_${latestVersion}`);
112
-
113
- if (fs.existsSync(binaryPath)) {
114
- return binaryPath; // Already on latest
115
- }
116
-
117
- // Delete old binaries
118
- const oldBinaries = fs.readdirSync(baseDir).filter(f => f.startsWith(binaryName));
119
- for (const old of oldBinaries) {
120
- fs.unlinkSync(path.join(baseDir, old));
121
- }
122
-
123
- process.stderr.write(`Downloading AgentSecrets v${latestVersion} for ${osName}/${archName}...\n`);
124
-
125
- const ext = osName === 'windows' ? 'zip' : 'tar.gz';
126
- const assetName = `agentsecrets_${latestVersion}_${osName}_${archName}.${ext}`;
127
- const url = `https://github.com/${GITHUB_REPO}/releases/download/v${latestVersion}/${assetName}`;
128
-
129
- const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'agentsecrets-'));
130
- const archivePath = path.join(tmpDir, assetName);
131
-
132
- try {
133
- await downloadFile(url, archivePath);
134
-
135
- if (ext === 'tar.gz') {
136
- await tar.x({ file: archivePath, cwd: tmpDir });
137
- } else {
138
- if (osName === 'windows') {
139
- throw new Error('Automatic zip extraction for Windows not yet implemented.');
140
- }
141
- }
142
-
143
- const extractedBinary = path.join(tmpDir, binaryName);
144
- fs.copyFileSync(extractedBinary, binaryPath);
145
- fs.chmodSync(binaryPath, 0o755);
146
- fs.rmSync(tmpDir, { recursive: true, force: true });
147
-
148
- return binaryPath;
149
- } catch (err) {
150
- throw new Error(`Failed to download AgentSecrets binary: ${err.message}`);
151
- }
152
- }
153
-
154
- async function main() {
155
- try {
156
- const binaryPath = await ensureBinary();
157
- const args = process.argv.slice(2);
158
- const child = spawn(binaryPath, args, { stdio: 'inherit' });
159
- child.on('exit', (code) => process.exit(code));
160
- } catch (err) {
161
- process.stderr.write(`Error: ${err.message}\n`);
162
- process.exit(1);
163
- }
164
- }
165
-
166
- main();
1
+ #!/usr/bin/env node
2
+
3
+ const fs = require('fs');
4
+ const path = require('path');
5
+ const os = require('os');
6
+ const { spawn } = require('child_process');
7
+ const https = require('https');
8
+ const tar = require('tar');
9
+
10
+ const PACKAGE_JSON = require('../package.json');
11
+ const VERSION = PACKAGE_JSON.version;
12
+ const GITHUB_REPO = "The-17/agentsecrets";
13
+
14
+ function getPlatformInfo() {
15
+ const type = os.type();
16
+ const arch = os.arch();
17
+
18
+ let os_name = '';
19
+ if (type === 'Darwin') os_name = 'darwin';
20
+ else if (type === 'Linux') os_name = 'linux';
21
+ else if (type === 'Windows_NT') os_name = 'windows';
22
+
23
+ let arch_name = '';
24
+ if (arch === 'x64') arch_name = 'amd64';
25
+ else if (arch === 'arm64') arch_name = 'arm64';
26
+ else if (arch === 'ia32') arch_name = '386';
27
+
28
+ return { os_name, arch_name };
29
+ }
30
+
31
+ async function downloadBinary(url, dest) {
32
+ return new Promise((resolve, reject) => {
33
+ https.get(url, (res) => {
34
+ if (res.statusCode === 302 || res.statusCode === 301) {
35
+ return downloadBinary(res.headers.location, dest).then(resolve).catch(reject);
36
+ }
37
+ if (res.statusCode !== 200) {
38
+ return reject(new Error(`Failed to download: ${res.statusCode}`));
39
+ }
40
+
41
+ const tempDir = path.join(os.tmpdir(), `agentsecrets-${Date.now()}`);
42
+ fs.mkdirSync(tempDir, { recursive: true });
43
+
44
+ const isWin = url.endsWith('.zip');
45
+
46
+ if (isWin) {
47
+ // Note: we don't have a zip library in dependencies,
48
+ // but GoReleaser can be configured to use tar.gz for all or
49
+ // we could use a simple unzip if available.
50
+ // For now, let's assume we use tar.gz for linux/darwin and
51
+ // if windows users use npm, they might need a zip tool or we use tar.gz there too.
52
+ // Actually, .goreleaser.yaml shows windows uses zip.
53
+ return reject(new Error("Windows zip extraction not yet implemented in NPM wrapper. Please use 'brew install agentsecrets' or download manually."));
54
+ }
55
+
56
+ res.pipe(tar.x({ C: tempDir }))
57
+ .on('finish', () => {
58
+ const binaryName = os.platform() === 'win32' ? 'agentsecrets.exe' : 'agentsecrets';
59
+ const src = path.join(tempDir, binaryName);
60
+ if (fs.existsSync(src)) {
61
+ fs.mkdirSync(path.dirname(dest), { recursive: true });
62
+ fs.renameSync(src, dest);
63
+ fs.chmodSync(dest, 0o755);
64
+ resolve();
65
+ } else {
66
+ reject(new Error(`Binary ${binaryName} not found in archive`));
67
+ }
68
+ })
69
+ .on('error', reject);
70
+ }).on('error', reject);
71
+ });
72
+ }
73
+
74
+ async function getLatestVersion() {
75
+ return new Promise((resolve, reject) => {
76
+ https.get({
77
+ hostname: 'api.github.com',
78
+ path: `/repos/${GITHUB_REPO}/releases/latest`,
79
+ headers: { 'User-Agent': 'agentsecrets-npm' }
80
+ }, (res) => {
81
+ let data = '';
82
+ res.on('data', (chunk) => data += chunk);
83
+ res.on('end', () => {
84
+ try {
85
+ const json = JSON.parse(data);
86
+ if (json.tag_name) {
87
+ resolve(json.tag_name.replace(/^v/, ''));
88
+ } else {
89
+ reject(new Error('No tag_name in latest release'));
90
+ }
91
+ } catch (e) {
92
+ reject(e);
93
+ }
94
+ });
95
+ }).on('error', reject);
96
+ });
97
+ }
98
+
99
+ async function getBinaryPath() {
100
+ const { os_name, arch_name } = getPlatformInfo();
101
+ const binDir = path.join(os.homedir(), '.agentsecrets', 'bin');
102
+ const binaryName = os_name === 'windows' ? 'agentsecrets.exe' : 'agentsecrets';
103
+
104
+ // Try to get the latest version from GitHub
105
+ let version = VERSION;
106
+ try {
107
+ version = await getLatestVersion();
108
+ } catch (err) {
109
+ console.error(`Failed to fetch latest version from GitHub: ${err.message}. Falling back to package version ${VERSION}.`);
110
+ }
111
+
112
+ const binaryPath = path.join(binDir, `${binaryName}_${version}`);
113
+
114
+ if (fs.existsSync(binaryPath)) {
115
+ return binaryPath;
116
+ }
117
+
118
+ console.error(`AgentSecrets binary not found. Downloading v${version} for ${os_name}/${arch_name}...`);
119
+
120
+ const ext = os_name === 'windows' ? 'zip' : 'tar.gz';
121
+ const assetName = `agentsecrets_${version}_${os_name}_${arch_name}.${ext}`;
122
+ const url = `https://github.com/${GITHUB_REPO}/releases/download/v${version}/${assetName}`;
123
+
124
+ try {
125
+ await downloadBinary(url, binaryPath);
126
+ return binaryPath;
127
+ } catch (err) {
128
+ throw new Error(`Failed to download AgentSecrets binary: ${err.message}\nURL: ${url}`);
129
+ }
130
+ }
131
+
132
+ async function main() {
133
+ try {
134
+ const binaryPath = await getBinaryPath();
135
+ const args = process.argv.slice(2);
136
+ const proc = spawn(binaryPath, args, { stdio: 'inherit' });
137
+ proc.on('close', (code) => process.exit(code || 0));
138
+ proc.on('error', (err) => {
139
+ console.error(`Failed to execute AgentSecrets: ${err.message}`);
140
+ process.exit(1);
141
+ });
142
+ } catch (err) {
143
+ console.error(err.message);
144
+ process.exit(1);
145
+ }
146
+ }
147
+
148
+ if (require.main === module) {
149
+ main();
150
+ }
151
+
152
+ module.exports = { getBinaryPath };
package/index.js ADDED
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @the-17/agentsecrets
3
+ * Zero-knowledge secrets infrastructure built for AI agents.
4
+ */
5
+
6
+ const { spawn } = require('child_process');
7
+ const path = require('path');
8
+ const { getBinaryPath } = require('./bin/agentsecrets');
9
+
10
+ /**
11
+ * Executes the agentsecrets CLI binary with the given arguments.
12
+ * @param {string[]} args
13
+ * @returns {Promise<number>}
14
+ */
15
+ async function run(args = []) {
16
+ const binaryPath = await getBinaryPath();
17
+ return new Promise((resolve, reject) => {
18
+ const proc = spawn(binaryPath, args, { stdio: 'inherit' });
19
+ proc.on('close', (code) => resolve(code));
20
+ proc.on('error', (err) => reject(err));
21
+ });
22
+ }
23
+
24
+ module.exports = {
25
+ run,
26
+ getBinaryPath
27
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@the-17/agentsecrets",
3
- "version": "1.1.4",
3
+ "version": "1.1.5",
4
4
  "description": "AI-native zero-knowledge secrets manager (CLI wrapper)",
5
5
  "main": "index.js",
6
6
  "bin": {