How captainflasmr/ollama-buddy works
Purpose and Entry Points
Ollama Buddy is an Emacs 29.1+ Lisp package for local Ollama chat and model management, extended with hosted and OpenAI-compatible LLM providers. The user-facing entry points are role and main Transient menus, which open/manage Org-native chat sessions. Package loading begins at ollama-buddy.el; chat lifecycle and shared state reside in ollama-buddy-core.el; menu composition is in ollama-buddy-transient.el.
Chat Runtime and Request Pipeline
Chat buffers collect prompts, conversation history, attachments, parameters, and response metadata, then stream results into Org-formatted output, including foldable reasoning blocks. Core dispatch supports Emacs network processes and a curl fallback; cancellation and error handling belong on this boundary. Relevant paths: ollama-buddy-core.el, ollama-buddy-curl.el, ollama-buddy-remote.el.
Provider Abstraction
ollama-buddy-provider.el is the central adapter layer: provider registrations define authentication, endpoint/model discovery, API type, and model prefixes. It translates the internal conversation/tool format into Ollama, OpenAI-compatible, Claude, or Gemini request formats. Provider-specific compatibility modules remain available for OpenAI, Claude, Gemini, Grok, Copilot, Codestral, DeepSeek, OpenRouter, and OpenCode. Paths: ollama-buddy-provider.el, ollama-buddy-openai-compat.el, ollama-buddy-claude.el, ollama-buddy-gemini.el.
Agentic Execution, Planning, and Project Context
The tools subsystem exposes registered Emacs operations—including file, buffer, shell, search, and evaluation capabilities—to model tool calls, with safe and unguarded execution modes. Plan mode converts model-produced work into Org TODO headings and executes steps with the same tool loop. Project integration supplies project-root context, summaries, and external-agent launch support. Paths: ollama-buddy-tools.el, ollama-buddy-plan.el, ollama-buddy-project.el, ollama-buddy-opencode.el.
Retrieval and Search
The RAG module indexes local documents/source, creates embeddings through Ollama /api/embed or an OpenAI-compatible embeddings service, and retrieves chunks for inline @rag expansion or tool calls. Web search is a distinct API integration used both inline and as a tool. Paths: ollama-buddy-rag.el, ollama-buddy-web-search.el, ollama-buddy-tools.el.
Editing and Coding Workflows
Prompt commands can target either chat or in-buffer rewriting. The rewrite subsystem streams candidate text into the source buffer, supports acceptance/rejection and diff presentation, and strips model formatting. A separate completion mode performs FIM-style inline code completion through Ollama generation. Paths: ollama-buddy-rewrite.el, ollama-buddy-completion.el, ollama-buddy-core.el.
Personas, Presets, and Annotation
Role presets define command/model/system-prompt configurations; user prompts and skills are Org-based content loaded into sessions or expanded inline. Directory annotation batches source files through a structured response workflow and applies project-relative annotations. Bundled editable content lives outside executable Lisp. Paths: ollama-buddy-user-prompts.el, ollama-buddy-presets/ollama-buddy--preset__developer.el, ollama-buddy-annotate.el, ollama-buddy-user-prompts/skills__Annotate-Project__system.org.
External Dependencies and Infrastructure
The primary local service is Ollama (/api/chat, model APIs, embeddings, cloud tags, and web search); remote services include OpenAI, Anthropic, Google Gemini, xAI, Mistral, DeepSeek, OpenRouter, GitHub Copilot, and arbitrary local OpenAI servers such as LM Studio/vLLM. Credentials are expected through Emacs auth-source. External coding agents and terminals are launched from Emacs; Pi integration is implemented in pi-extension/ollama-buddy-pi.ts. Reference docs are generated/maintained under docs/ollama-buddy.org.
Main entry points: ollama-buddy-core.el Chat runtime · ollama-buddy-provider.el Provider adapter · ollama-buddy-tools.el Tool execution loop · ollama-buddy-curl.el Request transport
Components 23
Emacs package
- Package entry · Loads the package and commands.
ollama-buddy.el - Role & main menus · Opens and manages chat workflows.
ollama-buddy-transient.el - Chat runtime · Owns prompts, history, attachments, streaming output, and lifecycle state.
ollama-buddy-core.el - Request transport · Dispatches requests and handles cancellation and errors.
ollama-buddy-curl.el - Remote requests
ollama-buddy-remote.el - Rewrite workflow · Streams candidate edits with diff and accept/reject controls.
ollama-buddy-rewrite.el - Inline completion
ollama-buddy-completion.el - Roles & prompts · Loads role configurations, user prompts, and skills.
ollama-buddy-user-prompts.el - Developer preset
ollama-buddy-presets/ollama-buddy--preset__developer.el
Provider layer
- Provider adapter · Converts internal conversations and tools to provider-specific APIs.
ollama-buddy-provider.el - OpenAI-compatible API
ollama-buddy-openai-compat.el - Claude provider
ollama-buddy-claude.el - Gemini provider
ollama-buddy-gemini.el
Automation & context
- Tool execution loop · Runs registered file, buffer, shell, search, and evaluation tools.
ollama-buddy-tools.el - Plan mode · Turns model work plans into executable tool-loop steps.
ollama-buddy-plan.el - Project context · Supplies project-root context, summaries, and agent launching.
ollama-buddy-project.el - RAG index & retrieval · Indexes local content, creates embeddings, and injects retrieved chunks.
ollama-buddy-rag.el - Web search · Supports inline expansion and tool calls.
ollama-buddy-web-search.el - Project annotation · Applies project-relative annotations to source files.
ollama-buddy-annotate.el
External services
- Ollama · Provides chat, generation, model, embedding, and search APIs.
- Hosted LLM APIs · OpenAI-compatible, Anthropic, Gemini, and other hosted models.
- auth-source
- Pi extension
pi-extension/ollama-buddy-pi.ts
Connections 23
- Package entry → Role & main menus: loads
- Package entry → Chat runtime: loads
- Role & main menus → Chat runtime: opens sessions
- Chat runtime → Request transport: dispatches requests
- Chat runtime → Provider adapter: selects provider
- Chat runtime → Rewrite workflow: targets edits
- Chat runtime → Inline completion: supports completion
- Chat runtime → Roles & prompts: loads role context
- Roles & prompts → Developer preset: includes
- Request transport → Ollama: local API
- Request transport → Remote requests: fallback / remote
- Remote requests → Hosted LLM APIs: API requests
- Provider adapter → OpenAI-compatible API: adapts
- Provider adapter → Claude provider: adapts
- Provider adapter → Gemini provider: adapts
- Provider adapter → auth-source: reads credentials
- Chat runtime → Tool execution loop: model tool calls
- Plan mode → Tool execution loop: executes steps
- Tool execution loop → RAG index & retrieval: retrieval tool
- Tool execution loop → Web search: search tool
- RAG index & retrieval → Provider adapter: embeddings request
- Project context → Pi extension: launches agent
- Project annotation → Tool execution loop: structured processing