@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.
- package/bin/agentsecrets.js +152 -166
- package/index.js +27 -0
- package/package.json +1 -1
package/bin/agentsecrets.js
CHANGED
|
@@ -1,166 +1,152 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const { spawn } = require('child_process');
|
|
7
|
-
const https = require('https');
|
|
8
|
-
const tar = require('tar');
|
|
9
|
-
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
+
};
|