Last Updated: 2026-01-07 Version: 1.0 (Refined Logic)
This document serves as the single source of truth for the technical implementation of Coder Buddy. It is designed to help AI agents and developers understand the codebase, logic flows, and project structure instantly.
Coder Buddy is a VS Code extension that provides a "Bipolar AI Companion" living in the sidebar.
- Type: Webview-based VS Code Extension.
- Core Philosophy: Client-side only. BYOK (Bring Your Own Key). Privacy-focused. "Chaotic Neutral" Personality.
- Main Tech Stack:
- Extension Host: TypeScript
- UI: React (Vite) + Tailwind CSS
- AI: OpenAI (
gpt-4o-mini) - Communication:
postMessage(Webview <-> Extension)
coder-buddy/
├── .vscode/ # VS Code launch & task configs
├── src/ # 🧠 EXTENSION BACKEND (Node.js environment)
│ ├── extension.ts # Entry point. Activates extension, registers providers.
│ └── services/
│ ├── SecretStorageService.ts # Custom service for secure API key storage.
│ ├── GatekeeperService.ts # Decides WHEN to trigger the AI (Debounce/Cost Control).
│ └── AIService.ts # Handles OpenAI calls, History/Memory, and Persona.
├── webview-ui/ # 🎨 UI FRONTEND (Browser environment)
│ ├── build/ # Output of Vite build (served to VS Code)
│ ├── src/
│ │ ├── components/ # React components (AvatarButton, SpeechBubble)
│ │ ├── helpers/ # UI helper functions
│ │ ├── hooks/ # Custom hooks (useCompanion.ts for logic)
│ │ ├── App.tsx # Main component & Animation Logic
│ │ └── index.css # Finite CSS Animations (Bounce/Shake)
│ └── vite.config.ts # Vite configuration
├── package.json # Extension manifest (activations, contributes)
└── architecture.md # Technical Documentation (YOU ARE HERE)
- Extension Activation (
src/extension.ts):- Extension activates on
onView:aiCompanion.sidebar. SecretStorageServiceinitializes.- Checks for stored OpenAI API Key (Prompt user if missing).
- Extension activates on
- Webview Initialization:
AICompanionViewProviderresolves the webview view.- Loads
index.html. - Sets strictly Content-Security-Policy (CSP).
Located in src/services/GatekeeperService.ts. Filters events to prevent spamming the AI.
The Filter Pipeline:
- Debounce: Wait for user to stop typing (3s).
- Diff Check: Code must change by >50 characters.
- Cooldown: 10 Seconds minimum between requests.
- RNG: 80% Chance to pass (20% random skip).
Located in src/services/AIService.ts.
- Model:
gpt-4o-mini(Cost-effective). - Context Window: Truncated to 4,000 characters to save tokens.
- Memory: Sliding window of last 10 messages.
- Optimization: Truncates old code snippets in history to
[Code snippet: Truncated]to prevent token inflation.
- Optimization: Truncates old code snippets in history to
- Persona System:
- Prompt Engineering: Enforces a "Chaotic Gen Z" personality.
- Mood Distribution:
- 25% Supportive/Hyped: "W code fr."
- 25% Chill/Vibing: "Code looks chill. ngl."
- 25% Toxic/Roasted: Roasts bad code ("NOOO what is this??").
- 25% Confused/Sus: "This logic is sus..."
- Rules: Do NOT roast valid code. Do NOT repeat previous comments.
Located in webview-ui/src/App.tsx and index.css.
- Finite Animations:
- Happy (Bounce): CSS
animation-iteration-count: 5(3.0s). - Angry (Shake): CSS
animation-iteration-count: 8(~3.2s). - Thinking (Pulse): Infinite loop until response arrives.
- Happy (Bounce): CSS
- Smooth Endings:
- Uses
animation-fill-mode: forwardsto stay at the final frame (grounded). - Uses React
keyprop (key={mood-text}) to force-remount the container on new messages, ensuring animations restart cleanly from frame 0 without snapping.
- Uses
- Targeting:
- Thinking Pulse -> Avatar Only.
- Bounce/Shake -> Entire Container (Avatar + Bubble).
extension.ts: Orchestrator. Connects VS Code Events -> Gatekeeper -> AI Service -> Webview.GatekeeperService.ts: The bouncer. Decides if we talk.AIService.ts: The mind. Talks to OpenAI, manages history.
App.tsx: State machine for Mood and Animation.AvatarButton.tsx: The face. AcceptsclassNamefor targeted animations.SpeechBubble.tsx: The voice.
- Webview: Built with Vite (
npm run build:watch). - Extension: Built with TSC (
npm run watch). - Run All:
npm run dev:all.
Tip: If changing
App.tsx,Cmd+Rthe Extension Host window to reload the webview cache.
- Privacy: Never send code unless Gatekeeper passes.
- Cost: Keep context < 4000 chars. Use
gpt-4o-mini. - Persona: Maintain the "Bipolar" vibe. Avoid being generic/robotic.