@@ -24,35 +24,12 @@ function getSentinelPath(opencodeHome: string): string {
2424 return path . join ( opencodeHome , 'data' , SENTINEL_FILE ) ;
2525}
2626
27- async function isCliInstalled ( command : string ) : Promise < boolean > {
28- try {
29- // Resolve command using Bun.which() to handle Windows .cmd files
30- const resolvedCommand = Bun . which ( command ) ?? command ;
31-
32- const proc = Bun . spawn ( [ resolvedCommand , '--version' ] , {
33- stdout : 'pipe' ,
34- stderr : 'pipe' ,
35- stdin : 'ignore' ,
36- } ) ;
37-
38- // Set a timeout
39- const timeout = new Promise < never > ( ( _ , reject ) =>
40- setTimeout ( ( ) => reject ( new Error ( 'Timeout' ) ) , 3000 )
41- ) ;
42-
43- const exitCode = await Promise . race ( [ proc . exited , timeout ] ) ;
44- const stdout = await new Response ( proc . stdout ) . text ( ) ;
45- const stderr = await new Response ( proc . stderr ) . text ( ) ;
46- const out = `${ stdout } \n${ stderr } ` ;
47-
48- if ( typeof exitCode === 'number' && exitCode === 0 ) return true ;
49- if ( / n o t r e c o g n i z e d a s a n i n t e r n a l o r e x t e r n a l c o m m a n d / i. test ( out ) ) return false ;
50- if ( / c o m m a n d n o t f o u n d / i. test ( out ) ) return false ;
51- if ( / N o s u c h f i l e o r d i r e c t o r y / i. test ( out ) ) return false ;
52- return false ;
53- } catch {
54- return false ;
55- }
27+ /**
28+ * Check if CLI binary exists in PATH (instant, no subprocess)
29+ * OpenCode works with zero config - just needs to be installed
30+ */
31+ function isCliInstalled ( command : string ) : boolean {
32+ return Bun . which ( command ) !== null ;
5633}
5734
5835function logInstallHelp ( ) : void {
@@ -70,24 +47,9 @@ function logInstallHelp(): void {
7047
7148
7249export async function isAuthenticated ( ) : Promise < boolean > {
73- // First check if CLI is installed
74- const cliInstalled = await isCliInstalled ( metadata . cliBinary ) ;
75- if ( ! cliInstalled ) {
76- return false ;
77- }
78-
79- // Check sentinel file (created after successful login via codemachine)
80- const opencodeHome = resolveOpenCodeHome ( ) ;
81- const sentinelPath = getSentinelPath ( opencodeHome ) ;
82- try {
83- await stat ( sentinelPath ) ;
84- return true ;
85- } catch {
86- // Sentinel not found, check OpenCode's native auth
87- }
88-
89- // Check OpenCode's native credential file
90- return hasOpenCodeCredential ( 'opencode' ) ;
50+ // OpenCode works with zero config - just needs to be installed
51+ // No auth check required; users can optionally login for specific APIs
52+ return isCliInstalled ( metadata . cliBinary ) ;
9153}
9254
9355/**
@@ -131,8 +93,7 @@ export async function ensureAuth(forceLogin = false): Promise<boolean> {
13193 await ensureDataDirExists ( dataDir ) ;
13294
13395 // Check if CLI is installed
134- const cliInstalled = await isCliInstalled ( metadata . cliBinary ) ;
135- if ( ! cliInstalled ) {
96+ if ( ! isCliInstalled ( metadata . cliBinary ) ) {
13697 logInstallHelp ( ) ;
13798 throw new Error ( `${ metadata . name } CLI is not installed.` ) ;
13899 }
0 commit comments