agentcontroll 1.0.4 → 1.0.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/lib/downloader.js +40 -1
- package/package.json +1 -1
package/lib/downloader.js
CHANGED
|
@@ -106,7 +106,28 @@ async function ensureBinary(binaryName = 'agentcontroll') {
|
|
|
106
106
|
}
|
|
107
107
|
}
|
|
108
108
|
|
|
109
|
-
// 3.
|
|
109
|
+
// 3. Check local workspace build directory if developing or testing within repo
|
|
110
|
+
const localCandidates = [
|
|
111
|
+
path.resolve(__dirname, '../../target/release', binaryName),
|
|
112
|
+
path.resolve(__dirname, '../../target/debug', binaryName),
|
|
113
|
+
path.resolve(__dirname, '../../../target/release', binaryName),
|
|
114
|
+
path.resolve(__dirname, '../../../target/debug', binaryName),
|
|
115
|
+
];
|
|
116
|
+
for (const candidate of localCandidates) {
|
|
117
|
+
if (fs.existsSync(candidate)) {
|
|
118
|
+
try {
|
|
119
|
+
fs.accessSync(candidate, fs.constants.X_OK);
|
|
120
|
+
return candidate;
|
|
121
|
+
} catch {
|
|
122
|
+
try {
|
|
123
|
+
fs.chmodSync(candidate, 0o755);
|
|
124
|
+
return candidate;
|
|
125
|
+
} catch {}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// 4. Need to download archive
|
|
110
131
|
const targetTriple = getTargetTriple();
|
|
111
132
|
const archiveName = getArchiveName(VERSION, targetTriple);
|
|
112
133
|
const baseUrl = process.env.AGENTCONTROL_DOWNLOAD_URL_BASE ||
|
|
@@ -149,6 +170,24 @@ async function ensureBinary(binaryName = 'agentcontroll') {
|
|
|
149
170
|
try {
|
|
150
171
|
if (fs.existsSync(tempArchive)) fs.unlinkSync(tempArchive);
|
|
151
172
|
} catch {}
|
|
173
|
+
|
|
174
|
+
// 5. Fallback: check if any other cached version exists before giving up
|
|
175
|
+
const baseBinDir = path.dirname(cacheDir);
|
|
176
|
+
if (fs.existsSync(baseBinDir)) {
|
|
177
|
+
try {
|
|
178
|
+
const versions = fs.readdirSync(baseBinDir)
|
|
179
|
+
.filter((v) => v.startsWith('v') && fs.existsSync(path.join(baseBinDir, v, binaryName)))
|
|
180
|
+
.sort()
|
|
181
|
+
.reverse();
|
|
182
|
+
if (versions.length > 0) {
|
|
183
|
+
const fallbackVersion = versions[0];
|
|
184
|
+
const fallbackPath = path.join(baseBinDir, fallbackVersion, binaryName);
|
|
185
|
+
process.stderr.write(`[agentcontroll] Warning: Could not download v${VERSION} (${err.message}). Using cached ${fallbackVersion} binary.\n`);
|
|
186
|
+
return fallbackPath;
|
|
187
|
+
}
|
|
188
|
+
} catch {}
|
|
189
|
+
}
|
|
190
|
+
|
|
152
191
|
throw new Error(
|
|
153
192
|
`Failed to download prebuilt AgentControll binary from ${archiveUrl}:\n${err.message}\n` +
|
|
154
193
|
`You can build from source using 'cargo build --release' or set AGENTCONTROL_BIN_DIR.`
|