From 7c983d798fa2ca9a366d75e4531d4fa7803ab021 Mon Sep 17 00:00:00 2001 From: "Mr. WorldwideBrown" Date: Sat, 11 Apr 2026 10:48:14 +0530 Subject: [PATCH] Fix OpenCode config path, FTS extension load order, error messages, and CLAUDE.md stats (#781) --- gitnexus-web/src/services/backend-client.ts | 4 ++- gitnexus/src/cli/ai-context.ts | 12 +++++++-- gitnexus/src/cli/analyze.ts | 5 +++- gitnexus/src/cli/index.ts | 1 + gitnexus/src/cli/setup.ts | 2 +- gitnexus/src/core/lbug/lbug-adapter.ts | 27 +++++++++++++-------- gitnexus/src/core/run-analyze.ts | 4 ++- 7 files changed, 39 insertions(+), 16 deletions(-) diff --git a/gitnexus-web/src/services/backend-client.ts b/gitnexus-web/src/services/backend-client.ts index d7862a63b..ebc18c17d 100644 --- a/gitnexus-web/src/services/backend-client.ts +++ b/gitnexus-web/src/services/backend-client.ts @@ -264,11 +264,13 @@ const fetchWithTimeout = async ( const assertOk = async (response: Response): Promise => { if (response.ok) return; - let message = `Backend returned ${response.status} ${response.statusText}`; + let message = response.statusText; try { const body = await response.json(); if (body && typeof body.error === 'string') { message = body.error; + } else if (body && typeof body.message === 'string') { + message = body.message; } } catch { // Response body was not JSON diff --git a/gitnexus/src/cli/ai-context.ts b/gitnexus/src/cli/ai-context.ts index 1c7a95d7a..ae7f984fb 100644 --- a/gitnexus/src/cli/ai-context.ts +++ b/gitnexus/src/cli/ai-context.ts @@ -26,6 +26,7 @@ interface RepoStats { export interface AIContextOptions { skipAgentsMd?: boolean; + noStats?: boolean; } const GITNEXUS_START_MARKER = ''; @@ -64,6 +65,7 @@ function generateGitNexusContent( stats: RepoStats, generatedSkills?: GeneratedSkillInfo[], groupNames?: string[], + noStats?: boolean, ): string { const generatedRows = generatedSkills && generatedSkills.length > 0 @@ -87,7 +89,7 @@ function generateGitNexusContent( return `${GITNEXUS_START_MARKER} # GitNexus — Code Intelligence -This project is indexed by GitNexus as **${projectName}** (${stats.nodes || 0} symbols, ${stats.edges || 0} relationships, ${stats.processes || 0} execution flows). Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. +This project is indexed by GitNexus as **${projectName}**${noStats ? '' : ` (${stats.nodes || 0} symbols, ${stats.edges || 0} relationships, ${stats.processes || 0} execution flows)`}. Use the GitNexus MCP tools to understand code, assess impact, and navigate safely. > If any GitNexus tool warns the index is stale, run \`npx gitnexus analyze\` in terminal first. @@ -332,7 +334,13 @@ export async function generateAIContextFiles( options?: AIContextOptions, ): Promise<{ files: string[] }> { const groupNames = await findGroupsContainingRegistryName(projectName); - const content = generateGitNexusContent(projectName, stats, generatedSkills, groupNames); + const content = generateGitNexusContent( + projectName, + stats, + generatedSkills, + groupNames, + options?.noStats, + ); const createdFiles: string[] = []; if (!options?.skipAgentsMd) { diff --git a/gitnexus/src/cli/analyze.ts b/gitnexus/src/cli/analyze.ts index c77903de0..d520c3404 100644 --- a/gitnexus/src/cli/analyze.ts +++ b/gitnexus/src/cli/analyze.ts @@ -47,6 +47,8 @@ export interface AnalyzeOptions { verbose?: boolean; /** Skip AGENTS.md and CLAUDE.md gitnexus block updates. */ skipAgentsMd?: boolean; + /** Omit volatile symbol/relationship counts from AGENTS.md and CLAUDE.md. */ + noStats?: boolean; /** Index the folder even when no .git directory is present. */ skipGit?: boolean; } @@ -177,6 +179,7 @@ export const analyzeCommand = async (inputPath?: string, options?: AnalyzeOption embeddings: options?.embeddings, skipGit: options?.skipGit, skipAgentsMd: options?.skipAgentsMd, + noStats: options?.noStats, }, { onProgress: (_phase, percent, message) => { @@ -240,7 +243,7 @@ export const analyzeCommand = async (inputPath?: string, options?: AnalyzeOption processes: s.processes, }, skillResult.skills, - { skipAgentsMd: options?.skipAgentsMd }, + { skipAgentsMd: options?.skipAgentsMd, noStats: options?.noStats }, ); } } catch { diff --git a/gitnexus/src/cli/index.ts b/gitnexus/src/cli/index.ts index 75940bcbf..02581ae47 100644 --- a/gitnexus/src/cli/index.ts +++ b/gitnexus/src/cli/index.ts @@ -26,6 +26,7 @@ program .option('--embeddings', 'Enable embedding generation for semantic search (off by default)') .option('--skills', 'Generate repo-specific skill files from detected communities') .option('--skip-agents-md', 'Skip updating the gitnexus section in AGENTS.md and CLAUDE.md') + .option('--no-stats', 'Omit volatile file/symbol counts from AGENTS.md and CLAUDE.md') .option('--skip-git', 'Index a folder without requiring a .git directory') .option('-v, --verbose', 'Enable verbose ingestion warnings (default: false)') .addHelpText( diff --git a/gitnexus/src/cli/setup.ts b/gitnexus/src/cli/setup.ts index ed941e6a4..8263405a5 100644 --- a/gitnexus/src/cli/setup.ts +++ b/gitnexus/src/cli/setup.ts @@ -265,7 +265,7 @@ async function setupOpenCode(result: SetupResult): Promise { return; } - const configPath = path.join(opencodeDir, 'config.json'); + const configPath = path.join(opencodeDir, 'opencode.json'); try { const existing = await readJsonFile(configPath); const config = existing || {}; diff --git a/gitnexus/src/core/lbug/lbug-adapter.ts b/gitnexus/src/core/lbug/lbug-adapter.ts index 88a6e9bba..90e663f40 100644 --- a/gitnexus/src/core/lbug/lbug-adapter.ts +++ b/gitnexus/src/core/lbug/lbug-adapter.ts @@ -909,19 +909,26 @@ export const loadFTSExtension = async (): Promise => { throw new Error('LadybugDB not initialized. Call initLbug first.'); } try { - await conn.query('INSTALL fts'); + // Try loading locally first (no network required) await conn.query('LOAD EXTENSION fts'); ftsLoaded = true; - } catch (err: any) { - const msg = err?.message || ''; - if ( - msg.includes('already loaded') || - msg.includes('already installed') || - msg.includes('already exists') - ) { + } catch { + // Fall back to install + load (requires network) + try { + await conn.query('INSTALL fts'); + await conn.query('LOAD EXTENSION fts'); ftsLoaded = true; - } else { - console.error('GitNexus: FTS extension load failed:', msg); + } catch (err: any) { + const msg = err?.message || ''; + if ( + msg.includes('already loaded') || + msg.includes('already installed') || + msg.includes('already exists') + ) { + ftsLoaded = true; + } else { + console.error('GitNexus: FTS extension load failed:', msg); + } } } }; diff --git a/gitnexus/src/core/run-analyze.ts b/gitnexus/src/core/run-analyze.ts index e8a108c71..f7b662705 100644 --- a/gitnexus/src/core/run-analyze.ts +++ b/gitnexus/src/core/run-analyze.ts @@ -48,6 +48,8 @@ export interface AnalyzeOptions { skipGit?: boolean; /** Skip AGENTS.md and CLAUDE.md gitnexus block updates. */ skipAgentsMd?: boolean; + /** Omit volatile symbol/relationship counts from AGENTS.md and CLAUDE.md. */ + noStats?: boolean; } export interface AnalyzeResult { @@ -327,7 +329,7 @@ export async function runFullAnalysis( processes: pipelineResult.processResult?.stats.totalProcesses, }, undefined, - { skipAgentsMd: options.skipAgentsMd }, + { skipAgentsMd: options.skipAgentsMd, noStats: options.noStats }, ); } catch { // Best-effort — don't fail the entire analysis for context file issues