@@ -6,7 +6,7 @@ import * as Schema from "effect/Schema";
66
77import type { ServerInstallation } from "@t3tools/contracts" ;
88import * as HostProcess from "@t3tools/shared/HostProcess" ;
9- import { isCommandAvailable } from "@t3tools/shared/shell" ;
9+ import { resolveCommandPath } from "@t3tools/shared/shell" ;
1010
1111import packageJson from "../../package.json" with { type : "json" } ;
1212
@@ -163,9 +163,25 @@ const resolveInstallLauncher = Effect.gen(function* () {
163163 : Option . none < string > ( ) ;
164164} ) ;
165165
166+ /**
167+ * A `t3` on PATH runs whichever install put it there, which may be an older npm global rather
168+ * than the desktop app that owns this server. It is this install's own only when it resolves to
169+ * the app's launcher; without a launcher to compare to, it is assumed to be.
170+ */
171+ const pathCommandIsOtherInstall = Effect . fn ( "invocation.pathCommandIsOtherInstall" ) ( function * (
172+ pathCommand : string ,
173+ ) {
174+ const shim = ( yield * HostProcess . Environment ) . T3CODE_CLI_PATH ?. trim ( ) ;
175+ if ( ! shim ) return false ;
176+ const fs = yield * FileSystem . FileSystem ;
177+ const real = ( file : string ) => fs . realPath ( file ) . pipe ( Effect . orElseSucceed ( ( ) => null ) ) ;
178+ const shimReal = yield * real ( shim ) ;
179+ return shimReal !== null && shimReal !== ( yield * real ( pathCommand ) ) ;
180+ } ) ;
181+
166182/**
167183 * `t3 <subcommand> <args>` for a person to run on this host: `t3` when it is
168- * on PATH, the package runner this process came from, or else the absolute
184+ * on PATH and is this install , the package runner this process came from, or else the absolute
169185 * path of the launcher for this install, such as the one the desktop app
170186 * installs. `args` are quoted for the host's shell: POSIX, or PowerShell on
171187 * Windows.
@@ -179,7 +195,10 @@ export const resolveHostCliCommand = Effect.fn("invocation.resolveHostCliCommand
179195 [ prefix , ...args . map ( ( arg ) => hostShellWord ( platform , arg ) ) ] . join ( " " ) ;
180196 const command = yield * resolveCliCommand ( subcommand ) ;
181197 if ( command !== `t3 ${ subcommand } ` ) return { command : withArgs ( command ) , launcher : false } ;
182- if ( yield * isCommandAvailable ( "t3" ) ) return { command : withArgs ( command ) , launcher : false } ;
198+ const onPath = yield * resolveCommandPath ( "t3" ) ;
199+ if ( onPath !== null && ! ( yield * pathCommandIsOtherInstall ( onPath ) ) ) {
200+ return { command : withArgs ( command ) , launcher : false } ;
201+ }
183202 const launcher = yield * resolveInstallLauncher ;
184203 if ( Option . isNone ( launcher ) ) return { command : withArgs ( command ) , launcher : false } ;
185204 // PowerShell runs a quoted path only through the call operator.
0 commit comments