@@ -48,6 +48,72 @@ function hasAutosearch() {
4848 return getInstalledAutosearchVersion ( ) !== null ;
4949}
5050
51+ function expectedAutosearchPath ( ) {
52+ if ( isWindows ( ) ) {
53+ return "%USERPROFILE%\\AppData\\Roaming\\Python\\Python312\\Scripts\\autosearch.exe" ;
54+ }
55+ return `${ process . env . HOME || "~" } /.local/bin/autosearch` ;
56+ }
57+
58+ function prependHomeLocalBinToPath ( ) {
59+ if ( ! process . env . HOME ) return ;
60+
61+ const localBin = `${ process . env . HOME } /.local/bin` ;
62+ const separator = isWindows ( ) ? ";" : ":" ;
63+ const currentPath = process . env . PATH || "" ;
64+ if ( currentPath . split ( separator ) . includes ( localBin ) ) return ;
65+
66+ process . env . PATH = currentPath
67+ ? `${ localBin } ${ separator } ${ currentPath } `
68+ : localBin ;
69+ }
70+
71+ function printAutosearchNotFoundHint ( error ) {
72+ process . stderr . write (
73+ `\nautosearch not found after install.\n` +
74+ `Expected executable: ${ expectedAutosearchPath ( ) } \n` +
75+ `Your PATH may not include the install location yet.\n` +
76+ `Re-source your shell profile or install AutoSearch directly:\n` +
77+ ` curl -fsSL ${ INSTALL_SCRIPT } | bash\n` +
78+ ` pipx install autosearch && autosearch init\n` +
79+ ` pip install --user autosearch && autosearch init\n` +
80+ ( error ?. message ? `\nOriginal error: ${ error . message } \n` : "\n" ) ,
81+ ) ;
82+ }
83+
84+ function printInstallerNotFoundHint ( error ) {
85+ process . stderr . write (
86+ `\nUnable to start the AutoSearch installer.\n` +
87+ `The underlying installer command was not found. Ensure one of these ` +
88+ `commands is available on PATH: curl, bash, pipx, py, python.\n` +
89+ `Then re-run: npx autosearch-ai --yes\n` +
90+ ( error ?. message ? `\nOriginal error: ${ error . message } \n` : "\n" ) ,
91+ ) ;
92+ }
93+
94+ function isPermissionError ( error ) {
95+ return error ?. code === "EACCES" || error ?. code === "EPERM" ;
96+ }
97+
98+ function printAutosearchPermissionHint ( error ) {
99+ process . stderr . write (
100+ `\nautosearch failed to start: permission denied.\n` +
101+ `Expected executable: ${ expectedAutosearchPath ( ) } \n` +
102+ `Check that the autosearch executable has execute permission, ` +
103+ `or reinstall AutoSearch with pipx or pip.\n` +
104+ ( error ?. message ? `\nOriginal error: ${ error . message } \n` : "\n" ) ,
105+ ) ;
106+ }
107+
108+ function printInstallerPermissionHint ( error ) {
109+ process . stderr . write (
110+ `\nUnable to start the AutoSearch installer: permission denied.\n` +
111+ `Check permissions for the installer command on PATH ` +
112+ `(bash, pipx, py, or python), then re-run: npx autosearch-ai --yes\n` +
113+ ( error ?. message ? `\nOriginal error: ${ error . message } \n` : "\n" ) ,
114+ ) ;
115+ }
116+
51117// Bug 6 (fix-plan v8 follow-up): compare the wrapper's expected Python CLI
52118// version against what's actually installed. The npm package version
53119// `YYYY.M.DD` derives from pyproject `YYYY.MM.DD.N` (N is the daily counter
@@ -150,7 +216,7 @@ function describeInstallStep() {
150216 if ( hasOnPath ( "python" ) ) return `python -m pip install --user autosearch` ;
151217 return null ;
152218 }
153- return `curl -fsSL ${ INSTALL_SCRIPT } | bash` ;
219+ return `curl -fsSL ${ INSTALL_SCRIPT } | bash -s -- --no-init ` ;
154220}
155221
156222function runInstall ( ) {
@@ -182,7 +248,7 @@ function runInstall() {
182248 }
183249 return spawnSync (
184250 "bash" ,
185- [ "-c" , `curl -fsSL ${ INSTALL_SCRIPT } | bash` ] ,
251+ [ "-c" , `curl -fsSL ${ INSTALL_SCRIPT } | bash -s -- --no-init ` ] ,
186252 { stdio : "inherit" } ,
187253 ) ;
188254}
@@ -226,15 +292,40 @@ async function main() {
226292 }
227293 }
228294 const result = runInstall ( ) ;
295+ if ( isPermissionError ( result . error ) ) {
296+ printInstallerPermissionHint ( result . error ) ;
297+ process . exit ( 1 ) ;
298+ }
299+ if ( result . error ?. code === "ENOENT" ) {
300+ printInstallerNotFoundHint ( result . error ) ;
301+ process . exit ( 1 ) ;
302+ }
303+ if ( result . error ) {
304+ printInstallerNotFoundHint ( result . error ) ;
305+ process . exit ( 1 ) ;
306+ }
229307 if ( ( result . status ?? 0 ) !== 0 ) {
230308 process . exit ( result . status ?? 1 ) ;
231309 }
310+ prependHomeLocalBinToPath ( ) ;
232311 } else {
233312 checkVersionAlignment ( installedVersion ) ;
234313 }
235314
236315 const cmd = args . length > 0 ? args : [ "init" ] ;
237316 const result = spawnSync ( "autosearch" , cmd , { stdio : "inherit" } ) ;
317+ if ( isPermissionError ( result . error ) ) {
318+ printAutosearchPermissionHint ( result . error ) ;
319+ process . exit ( 1 ) ;
320+ }
321+ if ( result . error ?. code === "ENOENT" ) {
322+ printAutosearchNotFoundHint ( result . error ) ;
323+ process . exit ( 1 ) ;
324+ }
325+ if ( result . error ) {
326+ printAutosearchNotFoundHint ( result . error ) ;
327+ process . exit ( 1 ) ;
328+ }
238329 process . exit ( result . status ?? 0 ) ;
239330}
240331
0 commit comments