Skip to content

Repository files navigation

Code Analyzer

A web application that takes a public GitHub repository URL and uses the Gemini Managed Agents API (antigravity-preview-05-2026) inside Google-hosted Linux container sandboxes to read, explore, and document the codebase. The application renders a multi-page PDF document and displays it in the web interface.


Key Features

  1. Sandbox Repository Mounting & Private Repositories (sources):

    • Uses the google-genai SDK and the Managed Agents API (client.interactions.create).
    • Provisions a Google-hosted Linux container (environment="remote").
    • Mounts public repositories directly, or authenticates private repositories using a GitHub Personal Access Token (PAT) mapped to basic credentials inside the remote container's network allowlist transforms.
  2. SSE Live Output and Terminal Logs:

    • Streams execution progress (stream=True) over Server-Sent Events (/api/jobs/{id}/stream).
    • Displays logs from bash inspection tools (tree, ast-grep, file reading) in the browser interface.
  3. ReportLab PDF Engine (pdf_generator.py):

    • Renders the Markdown architectural report into a PDF.
    • Includes cover headers, Page X of Y footers, code block boxes, and color styling.
  4. Web Interface (index.html):

    • Built with Tailwind CSS, Lucide Icons, and tabs:
      • Live Terminal & Logs Tab: Console showing sandbox status and agent tool calls.
      • Architectural Report Tab: Markdown rendering using marked.js and highlight.js.
      • PDF Document Tab: Embedded iframe allowing PDF inspection and downloads.
  5. Pluggable Agent Skills (skills/):

    • Stores the documentation layout structures, formatting guidelines, and syntax constraints inside a custom agent skill file (skills/repository_analyzer/SKILL.md).
    • Reads the local skill file at runtime and mounts it dynamically inside the remote sandbox workspace at .agents/skills/repository_analyzer/SKILL.md using the inline sources configuration.
    • Allows changing the output format or analysis scope by swapping or modifying the skill file.

Architecture and File Structure

code-analyzer/
├── app.py                # FastAPI server handling jobs, SSE streaming, and Managed Agents API
├── pdf_generator.py      # ReportLab PDF rendering engine with NumberedCanvas
├── index.html            # Tailwind frontend interface with logs viewer and PDF embed
├── requirements.txt      # Python dependencies
├── run.sh                # Launcher and virtual environment check script
└── output/               # Generated reports, jobs database (jobs.json), and PDF files

Quickstart

1. Set your Gemini API Key

export GEMINI_API_KEY="your_api_key_here"

2. Run the Application

You can use the helper script or run directly:

./run.sh
# OR via Python
.venv/bin/python app.py

3. Open the Web Interface

Navigate to http://localhost:8000 in your browser. Enter any public GitHub URL (or click one of the quick demo presets such as https://github.com/fastapi/fastapi) and click Launch Sandbox Agent & Render PDF.


API Endpoints

Method Endpoint Description
POST /api/analyze Initiates a new Managed Agent sandbox analysis job for a repository URL
GET /api/jobs Lists recent jobs and their execution/PDF status
GET /api/jobs/{job_id} Retrieves full job metadata, output markdown text, and execution logs
GET /api/jobs/{job_id}/stream SSE endpoint emitting real-time log lines, markdown deltas, and status updates
GET /api/jobs/{job_id}/pdf Serves the generated PDF report (?download=1 triggers file download)
GET /api/jobs/{job_id}/markdown Serves the raw generated Markdown architecture report

Managed Agent Configuration Details (app.py)

sources = [
    {
        "type": "repository",
        "source": repo_url,
        "target": "/workspace/repo",
    },
    {
        "type": "inline",
        "target": "/workspace/INSTRUCTIONS.md",
        "content": instructions
    }
]

if skill_content:
    sources.append({
        "type": "inline",
        "target": ".agents/skills/repository_analyzer/SKILL.md",
        "content": skill_content
    })

environment_config = {
    "type": "remote",
    "sources": sources
}

# Encode PAT and configure network allowlist transform for private repos
if github_token and github_token.strip():
    import base64
    token_val = github_token.strip()
    raw_credential = f"x-oauth-basic:{token_val}"
    base64_token = base64.b64encode(raw_credential.encode('utf-8')).decode('utf-8')
    environment_config["network"] = {
        "allowlist": [
            {
                "domain": "github.com",
                "transform": [
                    {
                        "Authorization": f"Basic {base64_token}"
                    }
                ]
            },
            {
                "domain": "*"
            }
        ]
    }

stream = client.interactions.create(
    agent="antigravity-preview-05-2026",
    input="Analyze the mounted repository in `/workspace/repo` following `/workspace/INSTRUCTIONS.md`...",
    environment=environment_config,
    stream=True,
)

About

A web application that takes a public GitHub repository URL and uses the Gemini Managed Agents API to read, explore, and document the codebase

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages