@@ -22,8 +22,35 @@ import { NON_INTERACTIVE_ENV_VARS } from "@/common/constants/env";
2222import { getBashPath } from "@/node/utils/main/bashPath" ;
2323import { EXIT_CODE_ABORTED , EXIT_CODE_TIMEOUT } from "@/common/constants/exitCodes" ;
2424import { DisposableProcess } from "@/node/utils/disposableExec" ;
25- import { expandTilde } from "./tildeExpansion" ;
2625import { getInitHookPath , createLineBufferedLoggers } from "./initHook" ;
26+ import { expandTilde } from "./tildeExpansion" ;
27+
28+ let cachedNicePath : string | null | undefined ;
29+
30+ async function resolveNicePath ( ) : Promise < string | null > {
31+ if ( cachedNicePath !== undefined ) {
32+ return cachedNicePath ;
33+ }
34+
35+ try {
36+ await fsPromises . access ( "/usr/bin/nice" ) ;
37+ cachedNicePath = "/usr/bin/nice" ;
38+ return cachedNicePath ;
39+ } catch {
40+ // continue
41+ }
42+
43+ try {
44+ await fsPromises . access ( "/bin/nice" ) ;
45+ cachedNicePath = "/bin/nice" ;
46+ return cachedNicePath ;
47+ } catch {
48+ // continue
49+ }
50+
51+ cachedNicePath = null ;
52+ return cachedNicePath ;
53+ }
2754
2855/**
2956 * Abstract base class for local runtimes (both WorktreeRuntime and LocalRuntime).
@@ -70,13 +97,7 @@ export abstract class LocalBaseRuntime implements Runtime {
7097 const bashPath = getBashPath ( ) ;
7198
7299 const shouldNice = options . niceness !== undefined && ! isWindows ;
73- const nicePath = shouldNice
74- ? fs . existsSync ( "/usr/bin/nice" )
75- ? "/usr/bin/nice"
76- : fs . existsSync ( "/bin/nice" )
77- ? "/bin/nice"
78- : null
79- : null ;
100+ const nicePath = shouldNice ? await resolveNicePath ( ) : null ;
80101
81102 const spawnCommand = nicePath ?? bashPath ;
82103 const spawnArgs =
0 commit comments