How theprimeagen/99 works
1. This is a Neovim plugin, not a standalone app.
The core runtime is Lua under lua/99, with Neovim as the host environment. The public entrypoint is require("99"), which exposes setup and high-level actions like search, visual, open, and request cancellation.
2. The plugin’s main purpose is agentic AI-assisted coding workflows.
The README and module layout show two dominant user flows:
- search/workflow mode: ask an AI to inspect the project and return findings into quickfix-style navigation
- visual edit mode: send the current visual selection to an AI and replace it with the result
These are the two central application paths the rest of the code supports.
3. Provider abstraction is a major boundary.
lua/99/providers.lua and the README show multiple external AI CLI backends behind one interface: OpenCode, Claude Code, Cursor Agent, and Gemini CLI. The plugin does not talk to an LLM API directly; it shells out through these provider CLIs. That means the architectural boundary is: Neovim plugin orchestration in-process, AI execution out-of-process.
4. Prompt construction is a separate subsystem.
Files like prompt.lua, prompt-settings.lua, ops/make-prompt.lua, and agents/helpers.lua indicate a dedicated layer for building request context. It assembles the user prompt plus optional project context from:
- referenced rules (#...)
- referenced files (@...)
- agent/skill markdown files
- extra rules passed through options
This is where user intent becomes the payload sent to the provider.
5. Context discovery is language-aware and filesystem-aware.
The queries/ directory contains Tree-sitter query files for C++, Elixir, Go, Java, Lua, Ruby, and TypeScript. These likely support extracting functions, imports, scopes, and calls for prompt context or code understanding. Separate file completion logic in extensions/files also scans the project, respecting git ignore rules when possible. So the repository has a static code-introspection layer plus a file-discovery layer.
6. Search, visual, and work are the three primary operations.
The ops/ directory is the application core:
- search.lua orchestrates project-wide AI analysis and produces locations/notes
- visual.lua or related logic handles selection-based transformations
- vibe.lua and tutorial.lua look like other interaction modes
- work extension adds persistent work tracking via extensions/work/worker.lua
These are not UI widgets; they are workflow coordinators that sit between prompt building and provider execution.
7. The plugin has a state and request-tracking layer.
state.lua, state/tracking.lua, ops/request_status.lua, in_flight_spec.lua, and throbber.lua point to lifecycle management for long-running jobs. The architecture tracks active requests, displays in-flight status, and supports cancellation/cleanup. This matters because the AI backend is asynchronous and potentially long-running.
8. Results are surfaced through Neovim-native UI components.
The repo includes window/ and ops/qfix-helpers.lua, showing that outputs are rendered either in custom windows or the quickfix list. window/select-window.lua and window/status-window.lua suggest dedicated review panes for past runs and progress/status. So output is not just text returned to the caller; it is routed into Neovim navigation surfaces.
9. Completion is a first-class UX layer for prompt composition.
extensions/completions.lua, extensions/cmp.lua, extensions/native.lua, and the README’s #rules / @files support show an autocomplete subsystem. It can use built-in completion or integrate with nvim-cmp / blink.cmp. This layer helps users discover skills and files before a request is sent, reducing prompt construction friction.
10. There is an extensibility layer for editor integrations.
extensions/telescope.lua, extensions/fzf_lua.lua, and extensions/pickers.lua provide provider/model selection UIs through popular picker plugins. extensions/agents and extensions/files suggest additional context helpers. The architecture separates core AI workflows from optional integrations, so the plugin can run with or without those extras.
11. Logging and debugging are treated as a separate operational concern.
logger/logger.lua and logger/level.lua show structured logging, with file output support mentioned in the README. This is important because the system orchestrates external CLIs and async requests; logs are the main observability boundary for diagnosing provider failures, prompt contents, and request lifecycle issues.
12. The repo includes test and CI infrastructure around the Lua core.
The lua/99/test/*_spec.lua suite covers most subsystems: requests, prompt building, state, completions, window behavior, worker flow, and more. CI is driven by Makefile, .github/workflows/makefile.yml, and helper scripts in scripts/ci and scripts/tests. This indicates the architecture is heavily unit-tested at the module boundary level rather than via a full end-to-end harness.
13. Documentation is generated from the codebase and README metadata.
docs/ contains a TypeScript doc generator, and files like README_HEADER.md and gen-docs imply docs are derived from source annotations and repository metadata. This is a support subsystem rather than runtime logic, but it matters for understanding how the API surface is kept in sync.
14. Overall data flow:
User action in Neovim → plugin entrypoint / ops module → prompt/context assembly (rules, files, tree-sitter, selection, work metadata) → provider CLI invocation → async tracking/logging/status UI → results rendered into quickfix, windows, or visual replacements.
The central architectural boundaries are therefore editor orchestration, context extraction, provider execution, and result presentation.
Main entry points: search.lua Search · init.lua Ops hub · prompt.lua Prompt builder · request_status.lua Request status
Components 24
Core runtime
Neovim-hosted Lua plugin logic and workflow orchestration.
- 99 entrypoint · Public Neovim entrypoint exposing setup and high-level actions.
lua/99/init.lua - Providers · Abstracts external AI CLI providers behind one interface.
lua/99/providers.lua - Tracking · Stores in-flight request metadata and lifecycle bookkeeping.
lua/99/state/tracking.lua
Context building
Prompt assembly, file discovery, and code-introspection helpers.
- Prompt builder · Builds request payloads from rules, files, skills, and options.
lua/99/prompt.lua - Prompt settings · Holds prompt-related defaults and configuration shaping.
lua/99/prompt-settings.lua - Agent helpers · Resolves agent and skill markdown context for prompts.
lua/99/extensions/agents/helpers.lua - File discovery · Finds project files while respecting ignore rules when possible.
lua/99/extensions/files/init.lua - Tree-sitter queries · Language-specific queries for extracting functions, imports, scopes, and calls.
queries/lua/99-function.scm
Editor UI
Neovim-facing presentation surfaces for status, selection, and navigation.
- Status window · Dedicated pane for progress and request state.
lua/99/window/status-window.lua - Select window · Pane for reviewing prior runs and selecting results.
lua/99/window/select-window.lua - Quickfix helpers · Converts results into quickfix-style navigation entries.
lua/99/ops/qfix-helpers.lua
Extensions
Optional integrations for providers, completions, pickers, and work tracking.
- Completions · Autocomplete layer for rules, files, and other prompt tokens.
lua/99/extensions/completions.lua - cmp bridge · Integrates prompt completion with nvim-cmp.
lua/99/extensions/cmp.lua - Native bridge · Provides built-in completion behavior without extra plugins.
lua/99/extensions/native.lua - Pickers · Selection UI abstraction for model and provider choices.
lua/99/extensions/pickers.lua - Telescope · Optional Telescope integration for selection workflows.
lua/99/extensions/telescope.lua - fzf-lua · Optional fzf-lua integration for selection workflows.
lua/99/extensions/fzf_lua.lua - Work worker · Tracks long-running work items and background progress.
lua/99/extensions/work/worker.lua
Operations
User-facing AI workflows and request lifecycle coordination.
- Make prompt · Combines operation inputs into the final request prompt.
lua/99/ops/make-prompt.lua - Search · Orchestrates project-wide AI analysis and navigation results.
lua/99/ops/search.lua - Ops hub · Coordinates operation entrypoints such as visual edits and other flows.
lua/99/ops/init.lua - Request status · Tracks active requests and their visible status.
lua/99/ops/request_status.lua
Support
Logging, docs, queries, tests, and automation around the core.
- Logger · Structured logging for provider calls, prompts, and lifecycle events.
lua/99/logger/logger.lua - Editor LSP · Neovim editor/LSP helpers used by workflows and context discovery.
lua/99/editor/lsp.lua
Connections 28
- 99 entrypoint → Search: search · Exposes the main project-analysis workflow.
- 99 entrypoint → Ops hub: ops · Routes high-level actions through the operations hub.
- 99 entrypoint → Providers: setup · Initializes provider selection and backend wiring.
- Ops hub → Request status: track · Coordinates lifecycle tracking for operation flows.
- Search → Make prompt: build · Constructs the request payload for search runs.
- Ops hub → Make prompt: build · Shares prompt composition across operations.
- Make prompt → Prompt builder: compose · Uses the shared prompt-building subsystem.
- Prompt builder → Prompt settings: defaults · Applies prompt configuration and defaults.
- Prompt builder → Agent helpers: skills · Pulls in agent and skill markdown context.
- Prompt builder → File discovery: files · Adds referenced project files to request context.
- Prompt builder → Tree-sitter queries: introspect · Uses language queries to extract code structure.
- Search → Providers: exec · Dispatches the analysis request through a CLI backend.
- Ops hub → Providers: exec · Dispatches workflow requests through a CLI backend.
- Providers → Logger: log · Records provider selection, prompts, and failures.
- Search → Request status: track · Updates request lifecycle state during analysis runs.
- Request status → Tracking: state · Persists in-flight request bookkeeping.
- Request status → Status window: render · Shows progress and request state in a dedicated pane.
- Search → Quickfix helpers: results · Turns findings into quickfix navigation entries.
- Search → Select window: review · Supports browsing and selecting prior results.
- Ops hub → Select window: preview · Surfaces transformed output for review.
- Completions → cmp bridge: adapter · Offers nvim-cmp integration for prompt completion.
- Completions → Native bridge: fallback · Provides built-in completion when no external plugin is used.
- Pickers → Telescope: adapter · Uses Telescope when available for selection UIs.
- Pickers → fzf-lua: adapter · Uses fzf-lua when available for selection UIs.
- Work worker → Search: feeds · Adds persistent work metadata into workflow runs.
- Work worker → Request status: monitor · Contributes background progress to request tracking.
- Editor LSP → Search: assist · Supports editor-aware analysis and navigation.
- Editor LSP → Ops hub: assist · Supports selection-aware editing flows.