mirror of
https://github.com/tiennm99/ccs.git
synced 2026-07-17 10:17:05 +00:00
refactor(utils): modularize websearch-manager into websearch/ directory
- extract gemini-cli, grok-cli, opencode-cli providers - extract hook-config, hook-env, hook-installer, status, types - slim websearch-manager.ts from 867 to 103 lines (88% reduction) - add barrel export at websearch/index.ts
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* OpenCode CLI Detection
|
||||
*
|
||||
* Detects and manages OpenCode CLI installation status.
|
||||
*
|
||||
* @module utils/websearch/opencode-cli
|
||||
*/
|
||||
|
||||
import { execSync } from 'child_process';
|
||||
import type { OpenCodeCliStatus } from './types';
|
||||
|
||||
// Cache for OpenCode CLI status (per process)
|
||||
let opencodeCliCache: OpenCodeCliStatus | null = null;
|
||||
|
||||
/**
|
||||
* Check if OpenCode CLI is installed globally
|
||||
*
|
||||
* OpenCode provides built-in web search via opencode/grok-code model.
|
||||
* Install: curl -fsSL https://opencode.ai/install | bash
|
||||
*
|
||||
* @returns OpenCode CLI status with path and version
|
||||
*/
|
||||
export function getOpenCodeCliStatus(): OpenCodeCliStatus {
|
||||
// Return cached result if available
|
||||
if (opencodeCliCache) {
|
||||
return opencodeCliCache;
|
||||
}
|
||||
|
||||
const result: OpenCodeCliStatus = {
|
||||
installed: false,
|
||||
path: null,
|
||||
version: null,
|
||||
};
|
||||
|
||||
try {
|
||||
const isWindows = process.platform === 'win32';
|
||||
const whichCmd = isWindows ? 'where opencode' : 'which opencode';
|
||||
|
||||
const pathResult = execSync(whichCmd, {
|
||||
encoding: 'utf8',
|
||||
timeout: 5000,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
|
||||
const opencodePath = pathResult.trim().split('\n')[0]; // First result on Windows
|
||||
|
||||
if (opencodePath) {
|
||||
result.installed = true;
|
||||
result.path = opencodePath;
|
||||
|
||||
// Try to get version
|
||||
try {
|
||||
const versionResult = execSync('opencode --version', {
|
||||
encoding: 'utf8',
|
||||
timeout: 5000,
|
||||
stdio: ['pipe', 'pipe', 'pipe'],
|
||||
});
|
||||
result.version = versionResult.trim();
|
||||
} catch {
|
||||
// Version check failed, but CLI is installed
|
||||
result.version = 'unknown';
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Command not found - OpenCode CLI not installed
|
||||
}
|
||||
|
||||
// Cache result
|
||||
opencodeCliCache = result;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if OpenCode CLI is available (quick boolean check)
|
||||
*/
|
||||
export function hasOpenCodeCli(): boolean {
|
||||
return getOpenCodeCliStatus().installed;
|
||||
}
|
||||
|
||||
/**
|
||||
* Clear OpenCode CLI cache (for testing or after installation)
|
||||
*/
|
||||
export function clearOpenCodeCliCache(): void {
|
||||
opencodeCliCache = null;
|
||||
}
|
||||
Reference in New Issue
Block a user