agentworth 0.1.9 → 0.1.10
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/resolver.js +38 -9
- package/package.json +1 -1
package/lib/resolver.js
CHANGED
|
@@ -411,9 +411,17 @@ export function resolveBinary(options = {}) {
|
|
|
411
411
|
}
|
|
412
412
|
}
|
|
413
413
|
|
|
414
|
+
// 4-7 all found a real, executable candidate but said nothing about whether it's the
|
|
415
|
+
// version this launcher is meant to run -- so a debug build from six releases ago,
|
|
416
|
+
// sitting in some worktree's target/ directory upward of wherever the user happened to
|
|
417
|
+
// invoke `agentworth` from, would silently win over the correctly-versioned release cache
|
|
418
|
+
// (8) forever. Same failure mode already fixed for PATH (3) above, same fix here: a
|
|
419
|
+
// candidate only counts if it reports the version this launcher ships.
|
|
420
|
+
const expectedVersion = getPackageVersion(baseDir);
|
|
421
|
+
|
|
414
422
|
// 4. Local Cargo target from working directory
|
|
415
423
|
const cwdCargoBin = findCargoTargetBinary(cwd, binName);
|
|
416
|
-
if (cwdCargoBin) {
|
|
424
|
+
if (cwdCargoBin && pathBinaryMatchesVersion(cwdCargoBin, expectedVersion)) {
|
|
417
425
|
return {
|
|
418
426
|
found: true,
|
|
419
427
|
path: cwdCargoBin,
|
|
@@ -423,7 +431,7 @@ export function resolveBinary(options = {}) {
|
|
|
423
431
|
|
|
424
432
|
// 5. Local Cargo target from package directory hierarchy
|
|
425
433
|
const pkgCargoBin = findCargoTargetBinary(baseDir, binName);
|
|
426
|
-
if (pkgCargoBin) {
|
|
434
|
+
if (pkgCargoBin && pathBinaryMatchesVersion(pkgCargoBin, expectedVersion)) {
|
|
427
435
|
return {
|
|
428
436
|
found: true,
|
|
429
437
|
path: pkgCargoBin,
|
|
@@ -434,7 +442,7 @@ export function resolveBinary(options = {}) {
|
|
|
434
442
|
// 6. CARGO_TARGET_DIR environment variable if specified
|
|
435
443
|
if (env.CARGO_TARGET_DIR) {
|
|
436
444
|
const targetDirRelease = path.join(env.CARGO_TARGET_DIR, 'release', binName);
|
|
437
|
-
if (isExecutable(targetDirRelease)) {
|
|
445
|
+
if (isExecutable(targetDirRelease) && pathBinaryMatchesVersion(targetDirRelease, expectedVersion)) {
|
|
438
446
|
return {
|
|
439
447
|
found: true,
|
|
440
448
|
path: targetDirRelease,
|
|
@@ -442,7 +450,7 @@ export function resolveBinary(options = {}) {
|
|
|
442
450
|
};
|
|
443
451
|
}
|
|
444
452
|
const targetDirDebug = path.join(env.CARGO_TARGET_DIR, 'debug', binName);
|
|
445
|
-
if (isExecutable(targetDirDebug)) {
|
|
453
|
+
if (isExecutable(targetDirDebug) && pathBinaryMatchesVersion(targetDirDebug, expectedVersion)) {
|
|
446
454
|
return {
|
|
447
455
|
found: true,
|
|
448
456
|
path: targetDirDebug,
|
|
@@ -454,7 +462,7 @@ export function resolveBinary(options = {}) {
|
|
|
454
462
|
// 7. User ~/.cargo/bin directory
|
|
455
463
|
if (homeDir) {
|
|
456
464
|
const cargoHomeBin = path.join(homeDir, '.cargo', 'bin', binName);
|
|
457
|
-
if (isExecutable(cargoHomeBin)) {
|
|
465
|
+
if (isExecutable(cargoHomeBin) && pathBinaryMatchesVersion(cargoHomeBin, expectedVersion)) {
|
|
458
466
|
return {
|
|
459
467
|
found: true,
|
|
460
468
|
path: cargoHomeBin,
|
|
@@ -462,8 +470,9 @@ export function resolveBinary(options = {}) {
|
|
|
462
470
|
};
|
|
463
471
|
}
|
|
464
472
|
|
|
465
|
-
// 8. User local cache (~/.agentworth/bin/v{version}/)
|
|
466
|
-
|
|
473
|
+
// 8. User local cache (~/.agentworth/bin/v{version}/) -- versioned by construction,
|
|
474
|
+
// nothing to check.
|
|
475
|
+
const cacheDir = getCacheDir(expectedVersion, homeDir);
|
|
467
476
|
const cachedBin = path.join(cacheDir, binName);
|
|
468
477
|
if (isExecutable(cachedBin)) {
|
|
469
478
|
return {
|
|
@@ -507,6 +516,23 @@ export function formatMissingBinaryMessage(platformKey = getPlatformKey()) {
|
|
|
507
516
|
].join('\n');
|
|
508
517
|
}
|
|
509
518
|
|
|
519
|
+
/**
|
|
520
|
+
* Builds the environment passed to the spawned native binary: the caller's base env plus
|
|
521
|
+
* the launcher markers the binary's `agentworth version`/`agentworth update` commands read
|
|
522
|
+
* to detect an npm-managed install (see `apps/cli/src/commands/version_info.rs`).
|
|
523
|
+
*
|
|
524
|
+
* @param {NodeJS.ProcessEnv} baseEnv
|
|
525
|
+
* @param {string} npmVersion
|
|
526
|
+
* @returns {NodeJS.ProcessEnv}
|
|
527
|
+
*/
|
|
528
|
+
export function buildChildEnv(baseEnv, npmVersion) {
|
|
529
|
+
return {
|
|
530
|
+
...baseEnv,
|
|
531
|
+
AGENTWORTH_LAUNCHER_ACTIVE: '1',
|
|
532
|
+
AGENTWORTH_NPM_VERSION: npmVersion,
|
|
533
|
+
};
|
|
534
|
+
}
|
|
535
|
+
|
|
510
536
|
/**
|
|
511
537
|
* Launches the native binary with the given arguments.
|
|
512
538
|
*
|
|
@@ -549,8 +575,11 @@ export function run(argv = process.argv.slice(2), options = {}) {
|
|
|
549
575
|
return 1;
|
|
550
576
|
}
|
|
551
577
|
|
|
552
|
-
// Belt and braces: a child that somehow re-enters this launcher cannot loop
|
|
553
|
-
|
|
578
|
+
// Belt and braces: a child that somehow re-enters this launcher cannot loop (the
|
|
579
|
+
// recursion guard in findPathBinary checks AGENTWORTH_LAUNCHER_ACTIVE). The npm version
|
|
580
|
+
// is threaded through too, purely so `agentworth version`/`agentworth update` can report
|
|
581
|
+
// it -- this launcher never reads it back itself.
|
|
582
|
+
const childEnv = buildChildEnv(options.env || process.env, getPackageVersion(options.baseDir || __dirname));
|
|
554
583
|
const result = spawnSync(binaryResult.path, resolvedArgs, {
|
|
555
584
|
stdio: 'inherit',
|
|
556
585
|
env: childEnv,
|