Skip to content

Repository files navigation

Rocket.Chat Code Analyzer (Gemini CLI Extension)

This project is an MCP-based Gemini CLI extension focused on context reduction for code analysis in large repositories.

Goal: help agentic workflows stay within strict token budgets by reducing unnecessary code context before inference.

What Is Implemented

This extension exposes the following tools:

  • analyze_directory
    • Builds a lightweight AST-based structure map of .js and .ts files.
  • search_codebase
    • Performs structural keyword matching against functions, classes, and limited JSDoc/file-name signals.
  • get_dependencies
    • Extracts shallow import/require dependencies for a target file.
  • view_file_skeleton
    • Returns a compressed code skeleton (signatures/types/classes, stripped implementations).
  • get_pruned_context
    • End-to-end pruning pipeline: search -> choose anchor file -> compress -> include dependencies until tokenBudget is reached.

Current Limitation (Important)

The semantic retrieval is currently basic and must be enhanced for production-scale conceptual queries.

  • search_codebase is mostly identifier-driven, not full semantic intent retrieval.
  • Natural language queries like "message sending flow" may return empty matches if similar identifiers are absent.
  • This is a known gap and the next planned improvement area.

Repository Structure

  • server.js: MCP server entry point and tool registration.
  • src/indexer.js: directory indexing (AST structure extraction).
  • src/searcher.js: structural keyword search.
  • src/dependency.js: dependency extraction.
  • src/compressor.js: skeleton/compression logic.
  • src/pipeline.js: budgeted pruned-context assembly pipeline.
  • gemini-extension.json: Gemini extension config.
  • GEMINI.md: operational prompt protocol for using tools efficiently.

How Others Can Use This On Their System

1) Prerequisites

  • Node.js 18+ (recommended)
  • npm
  • Gemini CLI with extension support

2) Get the Project

Clone/copy this folder to your machine, then open a terminal inside:

cd <path-to>/code-analyzer

3) Install Dependencies

npm install

4) Register/Load as a Local Gemini Extension

Use your Gemini CLI local extension workflow and point it to this folder (the folder that contains gemini-extension.json).

The extension starts server.js over stdio using:

  • command: node
  • args: ${extensionPath}/server.js

5) Verify It Is Loaded

Ask Gemini to run one of the tools, for example:

  • "Use analyze_directory on <absolute-project-path> and summarize the architecture."
  • "Use get_pruned_context with tokenBudget: 6000 for query buildPrunedContext."

You should see a tool execution line similar to:

  • get_pruned_context (code-analyzer MCP Server)

Example Usage Prompt

Use get_pruned_context on:
targetDirectory: D:\path\to\repo
query: "authentication flow"
tokenBudget: 6000

Then explain the critical modules and possible bug risks.

Notes

  • This is a working MVP extension for context reduction in code analysis.
  • It is intentionally focused on tooling mechanics, not full semantic retrieval quality yet.
  • Semantic ranking and conceptual search quality are the primary next improvement track before large-monorepo validation.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages