yaver-cli 1.99.168 → 1.99.171
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 +46 -0
package/package.json
CHANGED
package/src/agent-runtime.js
CHANGED
|
@@ -36,6 +36,25 @@ async function ensureAgentBinary({ quiet = false } = {}) {
|
|
|
36
36
|
const asset = await resolveAsset();
|
|
37
37
|
const localAgentPath = resolveLocalAgentBinary(asset);
|
|
38
38
|
if (localAgentPath) return localAgentPath;
|
|
39
|
+
// Defense in depth: if the cache holds a HIGHER version than
|
|
40
|
+
// what GH resolved, prefer it. Two failure modes this catches:
|
|
41
|
+
// 1. Older wrappers with the namespaced-tag-strip bug resolve
|
|
42
|
+
// to a stale legacy `v*` release even when newer `cli/v*`
|
|
43
|
+
// tags exist. Cache snapshot wins until npm catches up.
|
|
44
|
+
// 2. A new release publishes its tag but skips the platform
|
|
45
|
+
// asset (e.g. macOS notarize fails); falling back to a
|
|
46
|
+
// previously-cached newer build is better than running
|
|
47
|
+
// the older one.
|
|
48
|
+
const higherCached = findHigherCachedThan(asset.version);
|
|
49
|
+
if (higherCached) {
|
|
50
|
+
if (!quiet) {
|
|
51
|
+
console.error(
|
|
52
|
+
`[yaver] cache holds a newer agent (${higherCached.version}) than the resolved release ` +
|
|
53
|
+
`(${asset.version}); preferring cached binary.`,
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
return higherCached.path;
|
|
57
|
+
}
|
|
39
58
|
const installDir = path.join(CACHE_ROOT, asset.version, asset.cacheKey);
|
|
40
59
|
const binaryPath = path.join(installDir, asset.binaryName);
|
|
41
60
|
if (fs.existsSync(binaryPath)) {
|
|
@@ -62,6 +81,33 @@ async function ensureAgentBinary({ quiet = false } = {}) {
|
|
|
62
81
|
}
|
|
63
82
|
}
|
|
64
83
|
|
|
84
|
+
/** Walk CACHE_ROOT and return the path + version of any cached
|
|
85
|
+
* binary newer than `version` that matches this platform. Returns
|
|
86
|
+
* null when nothing higher is cached. Used as a "prefer-newer"
|
|
87
|
+
* override on top of the GH-resolved version. */
|
|
88
|
+
function findHigherCachedThan(version) {
|
|
89
|
+
if (!fs.existsSync(CACHE_ROOT)) return null;
|
|
90
|
+
if (!semver.valid(version)) return null;
|
|
91
|
+
const platform = process.platform;
|
|
92
|
+
const arch = process.arch;
|
|
93
|
+
const goArch = arch === 'x64' ? 'amd64' : arch === 'arm64' ? 'arm64' : arch;
|
|
94
|
+
const cacheKey = `${platform}-${goArch}`;
|
|
95
|
+
const binaryName = platform === 'win32' ? 'yaver.exe' : 'yaver';
|
|
96
|
+
const versions = fs.readdirSync(CACHE_ROOT).filter((v) => semver.valid(v));
|
|
97
|
+
versions.sort(semver.rcompare);
|
|
98
|
+
for (const v of versions) {
|
|
99
|
+
if (semver.lte(v, version)) break; // sorted desc; nothing higher remains
|
|
100
|
+
const p = path.join(CACHE_ROOT, v, cacheKey, binaryName);
|
|
101
|
+
if (fs.existsSync(p)) {
|
|
102
|
+
if (process.platform !== 'win32') {
|
|
103
|
+
try { fs.chmodSync(p, 0o755); } catch (_) {}
|
|
104
|
+
}
|
|
105
|
+
return { path: p, version: v };
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
|
|
65
111
|
/** Walk CACHE_ROOT and return the path to the newest yaver binary
|
|
66
112
|
* matching this platform — used as fallback when GH /releases is
|
|
67
113
|
* rate-limited and no specific version was resolvable. */
|