yaver-cli 1.99.133 → 1.99.134
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/package.json +1 -1
- package/src/agent-runtime.js +60 -5
package/package.json
CHANGED
package/src/agent-runtime.js
CHANGED
|
@@ -26,14 +26,69 @@ const EXECUTABLE_MAGICS = [
|
|
|
26
26
|
];
|
|
27
27
|
|
|
28
28
|
async function ensureAgentBinary({ quiet = false } = {}) {
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
// Try cache first — when the user already has any version of yaver
|
|
30
|
+
// installed locally, we shouldn't fail just because GitHub's API
|
|
31
|
+
// rate-limited the unauthenticated /releases call. Falling back to
|
|
32
|
+
// the cached binary keeps every yaver subcommand working through
|
|
33
|
+
// GH's daily rate-limit windows. Only call resolveAsset (which can
|
|
34
|
+
// throw on 403) when no cache hit AND no repo binary is present.
|
|
35
|
+
try {
|
|
36
|
+
const asset = await resolveAsset();
|
|
37
|
+
const localAgentPath = resolveLocalAgentBinary(asset);
|
|
38
|
+
if (localAgentPath) return localAgentPath;
|
|
39
|
+
const installDir = path.join(CACHE_ROOT, asset.version, asset.cacheKey);
|
|
40
|
+
const binaryPath = path.join(installDir, asset.binaryName);
|
|
41
|
+
if (fs.existsSync(binaryPath)) {
|
|
42
|
+
if (process.platform !== 'win32') fs.chmodSync(binaryPath, 0o755);
|
|
43
|
+
return binaryPath;
|
|
44
|
+
}
|
|
45
|
+
return await downloadAndCacheAgent(asset, { quiet });
|
|
46
|
+
} catch (err) {
|
|
47
|
+
// GH rate-limit OR network failure — try the most recent cached
|
|
48
|
+
// version so the user can continue using yaver. If nothing is
|
|
49
|
+
// cached either, surface the original error so the install path
|
|
50
|
+
// is clear.
|
|
51
|
+
const fallback = findMostRecentCachedAgent();
|
|
52
|
+
if (fallback) {
|
|
53
|
+
if (!quiet) {
|
|
54
|
+
console.error(
|
|
55
|
+
`[yaver] release lookup failed (${String(err.message || err).split('\n')[0]}); ` +
|
|
56
|
+
`using cached agent at ${fallback}`,
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
return fallback;
|
|
60
|
+
}
|
|
61
|
+
throw err;
|
|
33
62
|
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** Walk CACHE_ROOT and return the path to the newest yaver binary
|
|
66
|
+
* matching this platform — used as fallback when GH /releases is
|
|
67
|
+
* rate-limited and no specific version was resolvable. */
|
|
68
|
+
function findMostRecentCachedAgent() {
|
|
69
|
+
if (!fs.existsSync(CACHE_ROOT)) return null;
|
|
70
|
+
const platform = process.platform;
|
|
71
|
+
const arch = process.arch;
|
|
72
|
+
const goArch = arch === 'x64' ? 'amd64' : arch === 'arm64' ? 'arm64' : arch;
|
|
73
|
+
const cacheKey = `${platform}-${goArch}`;
|
|
74
|
+
const binaryName = platform === 'win32' ? 'yaver.exe' : 'yaver';
|
|
75
|
+
const versions = fs.readdirSync(CACHE_ROOT).filter((v) => semver.valid(v));
|
|
76
|
+
versions.sort(semver.rcompare);
|
|
77
|
+
for (const v of versions) {
|
|
78
|
+
const p = path.join(CACHE_ROOT, v, cacheKey, binaryName);
|
|
79
|
+
if (fs.existsSync(p)) {
|
|
80
|
+
if (process.platform !== 'win32') {
|
|
81
|
+
try { fs.chmodSync(p, 0o755); } catch (_) {}
|
|
82
|
+
}
|
|
83
|
+
return p;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
return null;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function downloadAndCacheAgent(asset, { quiet }) {
|
|
34
90
|
const installDir = path.join(CACHE_ROOT, asset.version, asset.cacheKey);
|
|
35
91
|
const binaryPath = path.join(installDir, asset.binaryName);
|
|
36
|
-
|
|
37
92
|
if (fs.existsSync(binaryPath)) {
|
|
38
93
|
if (process.platform !== 'win32') {
|
|
39
94
|
fs.chmodSync(binaryPath, 0o755);
|