Skip to content

Commit 3b1bb0b

Browse files
committed
refactor(opencode): simplify auth check by removing sentinel file verification
Remove complex CLI version check and sentinel file authentication in favor of simple binary existence check. OpenCode now works with zero config, only requiring CLI installation.
1 parent a51c5bb commit 3b1bb0b

File tree

1 file changed

+10
-49
lines changed
  • src/infra/engines/providers/opencode

1 file changed

+10
-49
lines changed

src/infra/engines/providers/opencode/auth.ts

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -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 (/not recognized as an internal or external command/i.test(out)) return false;
50-
if (/command not found/i.test(out)) return false;
51-
if (/No such file or directory/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

5835
function logInstallHelp(): void {
@@ -70,24 +47,9 @@ function logInstallHelp(): void {
7047

7148

7249
export 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

Comments
 (0)