@@ -77,12 +77,13 @@ export { formatCommand } from "./installRuntime";
7777let cachedFilesDir : string | null = null ;
7878
7979/**
80- * Get the terminal home directory from system.getFilesDir().
81- * This is where axs stores port files.
80+ * Get candidate Terminal data directories from system.getFilesDir().
81+ * Newer Terminal builds keep shared runtime state in public. Older builds used
82+ * alpine/home, and some installs keep it as a symlink for shell compatibility.
8283 */
83- async function getTerminalHomeDir ( ) : Promise < string > {
84+ async function getTerminalDataDirs ( ) : Promise < string [ ] > {
8485 if ( cachedFilesDir ) {
85- return `${ cachedFilesDir } /alpine/home` ;
86+ return [ `${ cachedFilesDir } /public` , ` ${ cachedFilesDir } / alpine/home`] ;
8687 }
8788
8889 const system = (
@@ -104,7 +105,7 @@ async function getTerminalHomeDir(): Promise<string> {
104105 system . getFilesDir (
105106 ( filesDir : string ) => {
106107 cachedFilesDir = filesDir ;
107- resolve ( `${ filesDir } /alpine/home` ) ;
108+ resolve ( [ `${ filesDir } /public` , ` ${ filesDir } / alpine/home`] ) ;
108109 } ,
109110 ( error : string ) => reject ( new Error ( error ) ) ,
110111 ) ;
@@ -115,14 +116,16 @@ async function getTerminalHomeDir(): Promise<string> {
115116 * Get the port file path for a given server and session.
116117 * Port file format: ~/.axs/lsp_ports/{serverName}_{session}
117118 */
118- async function getPortFilePath (
119+ async function getPortFilePaths (
119120 serverName : string ,
120121 session : string ,
121- ) : Promise < string > {
122- const homeDir = await getTerminalHomeDir ( ) ;
122+ ) : Promise < string [ ] > {
123+ const dataDirs = await getTerminalDataDirs ( ) ;
123124 // Use just the binary name (not full path), mirroring axs behavior
124125 const baseName = serverName . split ( "/" ) . pop ( ) || serverName ;
125- return `file://${ homeDir } /.axs/lsp_ports/${ baseName } _${ session } ` ;
126+ return dataDirs . map (
127+ ( dataDir ) => `file://${ dataDir } /.axs/lsp_ports/${ baseName } _${ session } ` ,
128+ ) ;
126129}
127130
128131/**
@@ -166,14 +169,16 @@ export async function getLspPort(
166169 session : string ,
167170) : Promise < PortInfo | null > {
168171 try {
169- const filePath = await getPortFilePath ( serverName , session ) ;
170- const port = await readPortFromFile ( filePath ) ;
172+ const filePaths = await getPortFilePaths ( serverName , session ) ;
171173
172- if ( port === null ) {
173- return null ;
174+ for ( const filePath of filePaths ) {
175+ const port = await readPortFromFile ( filePath ) ;
176+ if ( port !== null ) {
177+ return { port, filePath, session } ;
178+ }
174179 }
175180
176- return { port , filePath , session } ;
181+ return null ;
177182 } catch {
178183 return null ;
179184 }
@@ -1094,6 +1099,18 @@ export async function ensureServerRunning(
10941099 const key = server . id ;
10951100 if ( managedServers . has ( key ) ) {
10961101 const existing = managedServers . get ( key ) ;
1102+ if ( bridge && ! bridge . port ) {
1103+ if ( existing ?. port ) {
1104+ return { uuid : existing . uuid , discoveredPort : existing . port } ;
1105+ }
1106+ const portInfo = await getLspPort ( serverName , effectiveSession ) ;
1107+ if ( portInfo ) {
1108+ if ( existing ) {
1109+ existing . port = portInfo . port ;
1110+ }
1111+ return { uuid : existing ?. uuid ?? null , discoveredPort : portInfo . port } ;
1112+ }
1113+ }
10971114 return { uuid : existing ?. uuid ?? null } ;
10981115 }
10991116
@@ -1126,6 +1143,11 @@ export async function ensureServerRunning(
11261143 entry . port = discoveredPort ;
11271144 }
11281145 }
1146+ if ( ! discoveredPort ) {
1147+ throw new Error (
1148+ `Could not discover websocket bridge port for ${ server . id } ` ,
1149+ ) ;
1150+ }
11291151 } else if (
11301152 server . transport ?. url &&
11311153 ( server . transport . kind === "websocket" ||
0 commit comments