@apono-io/apono-mcp 0.2.39 → 0.2.41
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/download.js +43 -20
- package/lib/paths.js +11 -2
- package/package.json +1 -1
package/lib/download.js
CHANGED
|
@@ -5,7 +5,14 @@ const fs = require("fs");
|
|
|
5
5
|
const path = require("path");
|
|
6
6
|
const os = require("os");
|
|
7
7
|
const { execFileSync } = require("child_process");
|
|
8
|
-
const {
|
|
8
|
+
const {
|
|
9
|
+
BINARY_DIR,
|
|
10
|
+
BINARY_NAME,
|
|
11
|
+
BINARY_PREFIX,
|
|
12
|
+
BINARY_EXTENSION,
|
|
13
|
+
binaryPathForVersion,
|
|
14
|
+
RELEASES_BASE_URL,
|
|
15
|
+
} = require("./paths");
|
|
9
16
|
|
|
10
17
|
function getPackageVersion() {
|
|
11
18
|
const pkg = require("../package.json");
|
|
@@ -75,20 +82,35 @@ function httpsGet(url) {
|
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
84
|
|
|
78
|
-
|
|
85
|
+
// Used only when the version cannot be resolved, so that an offline start keeps
|
|
86
|
+
// working with whatever the machine already has.
|
|
87
|
+
function findNewestInstalledBinary() {
|
|
88
|
+
let entries;
|
|
79
89
|
try {
|
|
80
|
-
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
const output = execFileSync(BINARY_PATH, ["version"], {
|
|
84
|
-
encoding: "utf8",
|
|
85
|
-
timeout: 10000,
|
|
86
|
-
}).trim();
|
|
87
|
-
const match = output.match(/v?(\d+\.\d+\.\d+\S*)/);
|
|
88
|
-
return match ? match[1] : null;
|
|
90
|
+
entries = fs.readdirSync(BINARY_DIR);
|
|
89
91
|
} catch {
|
|
90
92
|
return null;
|
|
91
93
|
}
|
|
94
|
+
|
|
95
|
+
let newestPath = null;
|
|
96
|
+
let newestTime = -1;
|
|
97
|
+
for (const entry of entries) {
|
|
98
|
+
if (!entry.startsWith(BINARY_PREFIX) || !entry.endsWith(BINARY_EXTENSION)) {
|
|
99
|
+
continue;
|
|
100
|
+
}
|
|
101
|
+
const candidate = path.join(BINARY_DIR, entry);
|
|
102
|
+
try {
|
|
103
|
+
const stats = fs.statSync(candidate);
|
|
104
|
+
if (stats.isFile() && stats.mtimeMs > newestTime) {
|
|
105
|
+
newestPath = candidate;
|
|
106
|
+
newestTime = stats.mtimeMs;
|
|
107
|
+
}
|
|
108
|
+
} catch {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return newestPath;
|
|
92
114
|
}
|
|
93
115
|
|
|
94
116
|
async function getLatestVersion() {
|
|
@@ -134,7 +156,6 @@ function extractZip(archivePath, destDir) {
|
|
|
134
156
|
|
|
135
157
|
async function ensureBinary() {
|
|
136
158
|
const packageVersion = getPackageVersion();
|
|
137
|
-
const installedVersion = getInstalledVersion();
|
|
138
159
|
|
|
139
160
|
let targetVersion;
|
|
140
161
|
if (packageVersion !== "0.0.0") {
|
|
@@ -143,16 +164,18 @@ async function ensureBinary() {
|
|
|
143
164
|
try {
|
|
144
165
|
targetVersion = await getLatestVersion();
|
|
145
166
|
} catch (err) {
|
|
146
|
-
|
|
167
|
+
const installedBinary = findNewestInstalledBinary();
|
|
168
|
+
if (installedBinary) {
|
|
147
169
|
process.stderr.write(`Warning: Could not check for updates: ${err.message}\n`);
|
|
148
|
-
return
|
|
170
|
+
return installedBinary;
|
|
149
171
|
}
|
|
150
172
|
throw new Error(`Failed to fetch latest version: ${err.message}`);
|
|
151
173
|
}
|
|
152
174
|
}
|
|
153
175
|
|
|
154
|
-
|
|
155
|
-
|
|
176
|
+
const binaryPath = binaryPathForVersion(targetVersion);
|
|
177
|
+
if (fs.existsSync(binaryPath)) {
|
|
178
|
+
return binaryPath;
|
|
156
179
|
}
|
|
157
180
|
|
|
158
181
|
const platformStr = getPlatform();
|
|
@@ -185,7 +208,7 @@ async function ensureBinary() {
|
|
|
185
208
|
|
|
186
209
|
// Write to a temp file then atomically rename to avoid corruption
|
|
187
210
|
// if multiple processes run concurrently.
|
|
188
|
-
const tmpBinary =
|
|
211
|
+
const tmpBinary = binaryPath + ".tmp." + process.pid;
|
|
189
212
|
fs.copyFileSync(extractedBinary, tmpBinary);
|
|
190
213
|
fs.chmodSync(tmpBinary, 0o755);
|
|
191
214
|
|
|
@@ -203,14 +226,14 @@ async function ensureBinary() {
|
|
|
203
226
|
}
|
|
204
227
|
}
|
|
205
228
|
|
|
206
|
-
fs.renameSync(tmpBinary,
|
|
229
|
+
fs.renameSync(tmpBinary, binaryPath);
|
|
207
230
|
|
|
208
|
-
process.stderr.write(`Apono CLI v${targetVersion} installed to ${
|
|
231
|
+
process.stderr.write(`Apono CLI v${targetVersion} installed to ${binaryPath}\n`);
|
|
209
232
|
} finally {
|
|
210
233
|
fs.rmSync(tmpDir, { recursive: true, force: true });
|
|
211
234
|
}
|
|
212
235
|
|
|
213
|
-
return
|
|
236
|
+
return binaryPath;
|
|
214
237
|
}
|
|
215
238
|
|
|
216
239
|
module.exports = { ensureBinary };
|
package/lib/paths.js
CHANGED
|
@@ -7,11 +7,20 @@ const RELEASES_BASE_URL = "https://apono-agentic-releases.s3.amazonaws.com";
|
|
|
7
7
|
|
|
8
8
|
const BINARY_DIR = path.join(os.homedir(), ".local", "bin");
|
|
9
9
|
const BINARY_NAME = process.platform === "win32" ? "apono-agentic.exe" : "apono-agentic";
|
|
10
|
-
const
|
|
10
|
+
const BINARY_PREFIX = "apono-agentic-";
|
|
11
|
+
const BINARY_EXTENSION = process.platform === "win32" ? ".exe" : "";
|
|
12
|
+
|
|
13
|
+
// The version is part of the filename so that servers registered on different
|
|
14
|
+
// channels do not overwrite each other's binary between install and exec.
|
|
15
|
+
function binaryPathForVersion(version) {
|
|
16
|
+
return path.join(BINARY_DIR, `${BINARY_PREFIX}${version}${BINARY_EXTENSION}`);
|
|
17
|
+
}
|
|
11
18
|
|
|
12
19
|
module.exports = {
|
|
13
20
|
BINARY_DIR,
|
|
14
21
|
BINARY_NAME,
|
|
15
|
-
|
|
22
|
+
BINARY_PREFIX,
|
|
23
|
+
BINARY_EXTENSION,
|
|
24
|
+
binaryPathForVersion,
|
|
16
25
|
RELEASES_BASE_URL,
|
|
17
26
|
};
|