@agent-relay/utils 10.6.2 → 10.6.4
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.
|
@@ -34,6 +34,7 @@ __export(command_resolver_exports, {
|
|
|
34
34
|
module.exports = __toCommonJS(command_resolver_exports);
|
|
35
35
|
var import_node_child_process = require("node:child_process");
|
|
36
36
|
var import_node_fs = __toESM(require("node:fs"), 1);
|
|
37
|
+
var import_node_path = __toESM(require("node:path"), 1);
|
|
37
38
|
function resolveCommand(command) {
|
|
38
39
|
if (command.startsWith("/")) {
|
|
39
40
|
return resolveSymlinks(command);
|
|
@@ -63,7 +64,20 @@ function resolveCommand(command) {
|
|
|
63
64
|
function resolveSymlinks(filePath) {
|
|
64
65
|
try {
|
|
65
66
|
const resolved = import_node_fs.default.realpathSync(filePath);
|
|
66
|
-
if (resolved
|
|
67
|
+
if (resolved === filePath) {
|
|
68
|
+
return filePath;
|
|
69
|
+
}
|
|
70
|
+
const originalName = import_node_path.default.basename(filePath);
|
|
71
|
+
const resolvedName = import_node_path.default.basename(resolved);
|
|
72
|
+
if (originalName !== resolvedName) {
|
|
73
|
+
if (process.env.DEBUG_SPAWN === "1") {
|
|
74
|
+
console.log(
|
|
75
|
+
`[command-resolver] Preserving shim ${filePath} (target ${resolved} has a different basename \u2014 likely a mise/asdf-style dispatcher)`
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
return absolutizeShimPath(filePath);
|
|
79
|
+
}
|
|
80
|
+
if (process.env.DEBUG_SPAWN === "1") {
|
|
67
81
|
console.log(`[command-resolver] Resolved symlink: ${filePath} -> ${resolved}`);
|
|
68
82
|
}
|
|
69
83
|
return resolved;
|
|
@@ -74,6 +88,18 @@ function resolveSymlinks(filePath) {
|
|
|
74
88
|
return filePath;
|
|
75
89
|
}
|
|
76
90
|
}
|
|
91
|
+
function absolutizeShimPath(filePath) {
|
|
92
|
+
if (import_node_path.default.isAbsolute(filePath)) {
|
|
93
|
+
return filePath;
|
|
94
|
+
}
|
|
95
|
+
try {
|
|
96
|
+
const parent = import_node_path.default.dirname(filePath);
|
|
97
|
+
const canonicalParent = import_node_fs.default.realpathSync(parent === "" ? "." : parent);
|
|
98
|
+
return import_node_path.default.join(canonicalParent, import_node_path.default.basename(filePath));
|
|
99
|
+
} catch {
|
|
100
|
+
return filePath;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
77
103
|
function commandExists(command) {
|
|
78
104
|
try {
|
|
79
105
|
(0, import_node_child_process.execSync)(`which ${command}`, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-resolver.d.ts","sourceRoot":"","sources":["../src/command-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;
|
|
1
|
+
{"version":3,"file":"command-resolver.d.ts","sourceRoot":"","sources":["../src/command-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAgCtD;AAmED;;GAEG;AACH,wBAAgB,aAAa,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAUtD"}
|
package/dist/command-resolver.js
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
import { execSync } from 'node:child_process';
|
|
8
8
|
import fs from 'node:fs';
|
|
9
|
+
import path from 'node:path';
|
|
9
10
|
/**
|
|
10
11
|
* Resolve the full path of a command using 'which' and resolve any symlinks
|
|
11
12
|
* Returns the full path if found, or the original command if not found
|
|
@@ -41,14 +42,37 @@ export function resolveCommand(command) {
|
|
|
41
42
|
return command;
|
|
42
43
|
}
|
|
43
44
|
/**
|
|
44
|
-
* Resolve symlinks to get the actual file path
|
|
45
|
-
*
|
|
45
|
+
* Resolve symlinks to get the actual file path, preserving shim behaviour.
|
|
46
|
+
*
|
|
47
|
+
* Provider CLIs installed via version managers (mise, asdf, rtx, direnv,
|
|
48
|
+
* pkgx, jenv/pyenv/rbenv/nodenv/tfenv/volta, ...) are exposed as symlinked
|
|
49
|
+
* shims that all point at the manager binary. Those shims dispatch to the
|
|
50
|
+
* real tool based on `argv[0]` (the shim's own basename). If we canonicalise
|
|
51
|
+
* the shim we collapse it to the manager binary (`/opt/homebrew/bin/mise`) —
|
|
52
|
+
* the child then sees `argv[0] = "mise"` and the manager parses
|
|
53
|
+
* provider-specific flags like `--dangerously-bypass-approvals-and-sandbox`
|
|
54
|
+
* as its own arguments, aborting the worker before it can start.
|
|
55
|
+
*
|
|
56
|
+
* Rule: if realpath would change the executable's basename, treat it as a
|
|
57
|
+
* shim and keep the caller-facing path so `argv[0]` stays intact. Otherwise
|
|
58
|
+
* return the canonicalised path (still helps with posix_spawnp on hosts with
|
|
59
|
+
* quirky PATH handling, which is why this helper exists in the first place).
|
|
46
60
|
*/
|
|
47
61
|
function resolveSymlinks(filePath) {
|
|
48
62
|
try {
|
|
49
63
|
const resolved = fs.realpathSync(filePath);
|
|
50
|
-
|
|
51
|
-
|
|
64
|
+
if (resolved === filePath) {
|
|
65
|
+
return filePath;
|
|
66
|
+
}
|
|
67
|
+
const originalName = path.basename(filePath);
|
|
68
|
+
const resolvedName = path.basename(resolved);
|
|
69
|
+
if (originalName !== resolvedName) {
|
|
70
|
+
if (process.env.DEBUG_SPAWN === '1') {
|
|
71
|
+
console.log(`[command-resolver] Preserving shim ${filePath} (target ${resolved} has a different basename — likely a mise/asdf-style dispatcher)`);
|
|
72
|
+
}
|
|
73
|
+
return absolutizeShimPath(filePath);
|
|
74
|
+
}
|
|
75
|
+
if (process.env.DEBUG_SPAWN === '1') {
|
|
52
76
|
console.log(`[command-resolver] Resolved symlink: ${filePath} -> ${resolved}`);
|
|
53
77
|
}
|
|
54
78
|
return resolved;
|
|
@@ -62,6 +86,24 @@ function resolveSymlinks(filePath) {
|
|
|
62
86
|
return filePath;
|
|
63
87
|
}
|
|
64
88
|
}
|
|
89
|
+
/**
|
|
90
|
+
* Return an absolute path for `filePath` without following the final
|
|
91
|
+
* component's symlink, so `argv[0]` stays as the shim's basename when the
|
|
92
|
+
* child is spawned.
|
|
93
|
+
*/
|
|
94
|
+
function absolutizeShimPath(filePath) {
|
|
95
|
+
if (path.isAbsolute(filePath)) {
|
|
96
|
+
return filePath;
|
|
97
|
+
}
|
|
98
|
+
try {
|
|
99
|
+
const parent = path.dirname(filePath);
|
|
100
|
+
const canonicalParent = fs.realpathSync(parent === '' ? '.' : parent);
|
|
101
|
+
return path.join(canonicalParent, path.basename(filePath));
|
|
102
|
+
}
|
|
103
|
+
catch {
|
|
104
|
+
return filePath;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
65
107
|
/**
|
|
66
108
|
* Check if a command exists in PATH
|
|
67
109
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"command-resolver.js","sourceRoot":"","sources":["../src/command-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"command-resolver.js","sourceRoot":"","sources":["../src/command-resolver.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,MAAM,SAAS,CAAC;AACzB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;;;;GAIG;AACH,MAAM,UAAU,cAAc,CAAC,OAAe;IAC5C,qDAAqD;IACrD,IAAI,OAAO,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QAC5B,OAAO,eAAe,CAAC,OAAO,CAAC,CAAC;IAClC,CAAC;IAED,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,QAAQ,CAAC,SAAS,OAAO,EAAE,EAAE;YAC1C,QAAQ,EAAE,OAAO;YACjB,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;YAC/B,mCAAm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AO,KAAK,CAAC;IACf,CAAC;AACH,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@agent-relay/utils",
|
|
3
|
-
"version": "10.6.
|
|
3
|
+
"version": "10.6.4",
|
|
4
4
|
"description": "Shared utilities for agent-relay: logging, name generation, command resolution, update checking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/cjs/index.js",
|
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
"vitest": "^4.1.0"
|
|
107
107
|
},
|
|
108
108
|
"dependencies": {
|
|
109
|
-
"@agent-relay/config": "10.6.
|
|
109
|
+
"@agent-relay/config": "10.6.4",
|
|
110
110
|
"compare-versions": "^6.1.1"
|
|
111
111
|
},
|
|
112
112
|
"publishConfig": {
|