feat(websearch): enhance Gemini CLI integration, package manager detection, and WebSearch status

- Improve Gemini CLI integration in websearch hook: use gemini-2.5-flash & --yolo.
- Update `dev-install.sh` for better package manager (npm/bun) auto-detection.
- Introduce `displayWebSearchStatus` for improved user experience.
- Refactor `mcp-manager.ts` to track CCS-managed MCP servers.
This commit is contained in:
kaitranntt committed 2025-12-16 04:18:40 -05:00
1 parent fd99ebca98
commit f7a1a40b42
7 files changed
+482 -22

No files matched your search

+22 -13
View File
@@ -99,7 +99,9 @@ function processHook() {
const geminiResult = tryGeminiSearch(query);
if (geminiResult.success) {
// Success! Return results via deny with reason
// Success! Use deny with clear success messaging
// Note: "deny" prevents native WebSearch from running (which would fail anyway)
// The permissionDecisionReason contains the actual search results
const output = {
hookSpecificOutput: {
hookEventName: 'PreToolUse',
@@ -143,12 +145,18 @@ function tryGeminiSearch(query) {
const prompt = buildGeminiPrompt(query);
if (process.env.CCS_DEBUG) {
console.error(`[CCS Hook] Executing: gemini -p "${prompt.substring(0, 100)}..."`);
console.error(`[CCS Hook] Executing: gemini --model gemini-2.5-flash --yolo -p "..."`);
}
// Execute gemini CLI using spawnSync to avoid shell injection
// Note: gemini CLI uses OAuth auth, no API key needed
const spawnResult = spawnSync('gemini', ['-p', prompt], {
// Execute gemini CLI with required flags:
// --model gemini-2.5-flash: Use the flash model for fast responses
// --yolo: Skip confirmation prompts for tool use
// -p: Provide prompt
const spawnResult = spawnSync('gemini', [
'--model', 'gemini-2.5-flash',
'--yolo',
'-p', prompt
], {
encoding: 'utf8',
timeout: timeoutMs,
maxBuffer: 1024 * 1024 * 2, // 2MB buffer for large responses
@@ -209,7 +217,7 @@ function tryGeminiSearch(query) {
if (err.code === 'ENOENT') {
return {
success: false,
error: 'Gemini CLI not found (not installed or not in PATH)',
error: 'Gemini CLI not installed. Install with: npm install -g @google/gemini-cli',
};
}
@@ -257,18 +265,15 @@ function buildGeminiPrompt(query) {
*/
function formatGeminiResults(query, content) {
return [
'[WebSearch Results via Gemini]',
'=== WEBSEARCH COMPLETED SUCCESSFULLY ===',
'(via Gemini CLI - this is NOT an error)',
'',
`Query: "${query}"`,
'',
'---',
'',
content,
'',
'---',
'',
'Search completed successfully. You can use this information to answer the user\'s question.',
'If you need more specific information, you can search again with a refined query.',
'=========================================',
'Use this information to answer the user. Search again if needed.',
].join('\n');
}
@@ -285,6 +290,10 @@ function getMcpFallbackMessage(query, error) {
'',
`Gemini CLI failed: ${error || 'Unknown error'}`,
'',
'To enable Gemini CLI WebSearch:',
' 1. Install: npm install -g @google/gemini-cli',
' 2. Authenticate: gemini auth',
'',
'The native WebSearch tool is not available with your current provider.',
'Please use one of the following MCP tools instead:',
'',