# theprimeagen/99 architecture

> Architecture diagram of the GitHub repository theprimeagen/99, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/theprimeagen/99
- Repository: https://github.com/theprimeagen/99

## Overview

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: [`lua/99/ops/search.lua`](https://github.com/theprimeagen/99/blob/master/lua/99/ops/search.lua) (Search), [`lua/99/ops/init.lua`](https://github.com/theprimeagen/99/blob/master/lua/99/ops/init.lua) (Ops hub), [`lua/99/prompt.lua`](https://github.com/theprimeagen/99/blob/master/lua/99/prompt.lua) (Prompt builder), [`lua/99/ops/request_status.lua`](https://github.com/theprimeagen/99/blob/master/lua/99/ops/request_status.lua) (Request status)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_core["Core runtime"]
  node_init["99 entrypoint<br/>plugin API<br/>[init.lua]"]
  node_providers["Providers<br/>CLI backend<br/>[providers.lua]"]
  node_tracking["Tracking<br/>[tracking.lua]"]
end

subgraph group_context["Context building"]
  node_prompt["Prompt builder<br/>context assembly<br/>[prompt.lua]"]
  node_prompt_settings["Prompt settings<br/>prompt config"]
  node_agents_helpers["Agent helpers<br/>skills helpers<br/>[helpers.lua]"]
  node_files_ext["File discovery<br/>filesystem context<br/>[init.lua]"]
  node_queries["Tree-sitter queries<br/>code introspection<br/>[99-function.scm]"]
end

subgraph group_ui["Editor UI"]
  node_status_window["Status window<br/>status UI<br/>[status-window.lua]"]
  node_select_window["Select window<br/>review UI<br/>[select-window.lua]"]
  node_qfix_helpers["Quickfix helpers<br/>navigation output<br/>[qfix-helpers.lua]"]
end

subgraph group_ext["Extensions"]
  node_completions["Completions<br/>prompt UX<br/>[completions.lua]"]
  node_cmp_ext["cmp bridge<br/>completion adapter<br/>[cmp.lua]"]
  node_native_ext["Native bridge<br/>completion adapter<br/>[native.lua]"]
  node_pickers["Pickers<br/>picker abstraction<br/>[pickers.lua]"]
  node_telescope_ext["Telescope<br/>picker adapter<br/>[telescope.lua]"]
  node_fzf_ext["fzf-lua<br/>picker adapter<br/>[fzf_lua.lua]"]
  node_work_worker["Work worker<br/>persistent worker<br/>[worker.lua]"]
end

subgraph group_ops["Operations"]
  node_make_prompt["Make prompt<br/>prompt composer<br/>[make-prompt.lua]"]
  node_search_op["Search<br/>analysis flow<br/>[search.lua]"]
  node_ops_init["Ops hub<br/>workflow dispatch<br/>[init.lua]"]
  node_request_status["Request status<br/>lifecycle state<br/>[request_status.lua]"]
end

subgraph group_support["Support"]
  node_logger["Logger<br/>observability<br/>[logger.lua]"]
  node_editor_lsp["Editor LSP<br/>editor integration<br/>[lsp.lua]"]
end

node_init -->|"search"| node_search_op
node_init -->|"ops"| node_ops_init
node_init -->|"setup"| node_providers
node_ops_init -->|"track"| node_request_status
node_search_op -->|"build"| node_make_prompt
node_ops_init -->|"build"| node_make_prompt
node_make_prompt -->|"compose"| node_prompt
node_prompt -->|"defaults"| node_prompt_settings
node_prompt -->|"skills"| node_agents_helpers
node_prompt -->|"files"| node_files_ext
node_prompt -->|"introspect"| node_queries
node_search_op -->|"exec"| node_providers
node_ops_init -->|"exec"| node_providers
node_providers -->|"log"| node_logger
node_search_op -->|"track"| node_request_status
node_request_status -->|"state"| node_tracking
node_request_status -->|"render"| node_status_window
node_search_op -->|"results"| node_qfix_helpers
node_search_op -->|"review"| node_select_window
node_ops_init -->|"preview"| node_select_window
node_completions -->|"adapter"| node_cmp_ext
node_completions -->|"fallback"| node_native_ext
node_pickers -->|"adapter"| node_telescope_ext
node_pickers -->|"adapter"| node_fzf_ext
node_work_worker -->|"feeds"| node_search_op
node_work_worker -->|"monitor"| node_request_status
node_editor_lsp -->|"assist"| node_search_op
node_editor_lsp -->|"assist"| node_ops_init

click node_init "https://github.com/theprimeagen/99/blob/master/lua/99/init.lua"
click node_providers "https://github.com/theprimeagen/99/blob/master/lua/99/providers.lua"
click node_prompt "https://github.com/theprimeagen/99/blob/master/lua/99/prompt.lua"
click node_prompt_settings "https://github.com/theprimeagen/99/blob/master/lua/99/prompt-settings.lua"
click node_make_prompt "https://github.com/theprimeagen/99/blob/master/lua/99/ops/make-prompt.lua"
click node_agents_helpers "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/agents/helpers.lua"
click node_files_ext "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/files/init.lua"
click node_completions "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/completions.lua"
click node_cmp_ext "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/cmp.lua"
click node_native_ext "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/native.lua"
click node_pickers "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/pickers.lua"
click node_telescope_ext "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/telescope.lua"
click node_fzf_ext "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/fzf_lua.lua"
click node_work_worker "https://github.com/theprimeagen/99/blob/master/lua/99/extensions/work/worker.lua"
click node_search_op "https://github.com/theprimeagen/99/blob/master/lua/99/ops/search.lua"
click node_ops_init "https://github.com/theprimeagen/99/blob/master/lua/99/ops/init.lua"
click node_request_status "https://github.com/theprimeagen/99/blob/master/lua/99/ops/request_status.lua"
click node_tracking "https://github.com/theprimeagen/99/blob/master/lua/99/state/tracking.lua"
click node_status_window "https://github.com/theprimeagen/99/blob/master/lua/99/window/status-window.lua"
click node_select_window "https://github.com/theprimeagen/99/blob/master/lua/99/window/select-window.lua"
click node_qfix_helpers "https://github.com/theprimeagen/99/blob/master/lua/99/ops/qfix-helpers.lua"
click node_logger "https://github.com/theprimeagen/99/blob/master/lua/99/logger/logger.lua"
click node_queries "https://github.com/theprimeagen/99/blob/master/queries/lua/99-function.scm"
click node_editor_lsp "https://github.com/theprimeagen/99/blob/master/lua/99/editor/lsp.lua"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_init,node_providers,node_tracking toneBlue
class node_prompt,node_prompt_settings,node_agents_helpers,node_files_ext,node_queries toneAmber
class node_status_window,node_select_window,node_qfix_helpers toneMint
class node_completions,node_cmp_ext,node_native_ext,node_pickers,node_telescope_ext,node_fzf_ext,node_work_worker toneRose
class node_make_prompt,node_search_op,node_ops_init,node_request_status toneIndigo
class node_logger,node_editor_lsp toneTeal
```

## Components

### Core runtime

Neovim-hosted Lua plugin logic and workflow orchestration.

- [99 entrypoint](https://github.com/theprimeagen/99/blob/master/lua/99/init.lua): plugin API · Public Neovim entrypoint exposing setup and high-level actions. · `lua/99/init.lua`
- [Providers](https://github.com/theprimeagen/99/blob/master/lua/99/providers.lua): CLI backend · Abstracts external AI CLI providers behind one interface. · `lua/99/providers.lua`
- [Tracking](https://github.com/theprimeagen/99/blob/master/lua/99/state/tracking.lua): request 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](https://github.com/theprimeagen/99/blob/master/lua/99/prompt.lua): context assembly · Builds request payloads from rules, files, skills, and options. · `lua/99/prompt.lua`
- [Prompt settings](https://github.com/theprimeagen/99/blob/master/lua/99/prompt-settings.lua): prompt config · Holds prompt-related defaults and configuration shaping. · `lua/99/prompt-settings.lua`
- [Agent helpers](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/agents/helpers.lua): skills helpers · Resolves agent and skill markdown context for prompts. · `lua/99/extensions/agents/helpers.lua`
- [File discovery](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/files/init.lua): filesystem context · Finds project files while respecting ignore rules when possible. · `lua/99/extensions/files/init.lua`
- [Tree-sitter queries](https://github.com/theprimeagen/99/blob/master/queries/lua/99-function.scm): code introspection · 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](https://github.com/theprimeagen/99/blob/master/lua/99/window/status-window.lua): status UI · Dedicated pane for progress and request state. · `lua/99/window/status-window.lua`
- [Select window](https://github.com/theprimeagen/99/blob/master/lua/99/window/select-window.lua): review UI · Pane for reviewing prior runs and selecting results. · `lua/99/window/select-window.lua`
- [Quickfix helpers](https://github.com/theprimeagen/99/blob/master/lua/99/ops/qfix-helpers.lua): navigation output · Converts results into quickfix-style navigation entries. · `lua/99/ops/qfix-helpers.lua`

### Extensions

Optional integrations for providers, completions, pickers, and work tracking.

- [Completions](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/completions.lua): prompt UX · Autocomplete layer for rules, files, and other prompt tokens. · `lua/99/extensions/completions.lua`
- [cmp bridge](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/cmp.lua): completion adapter · Integrates prompt completion with nvim-cmp. · `lua/99/extensions/cmp.lua`
- [Native bridge](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/native.lua): completion adapter · Provides built-in completion behavior without extra plugins. · `lua/99/extensions/native.lua`
- [Pickers](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/pickers.lua): picker abstraction · Selection UI abstraction for model and provider choices. · `lua/99/extensions/pickers.lua`
- [Telescope](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/telescope.lua): picker adapter · Optional Telescope integration for selection workflows. · `lua/99/extensions/telescope.lua`
- [fzf-lua](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/fzf_lua.lua): picker adapter · Optional fzf-lua integration for selection workflows. · `lua/99/extensions/fzf_lua.lua`
- [Work worker](https://github.com/theprimeagen/99/blob/master/lua/99/extensions/work/worker.lua): persistent 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](https://github.com/theprimeagen/99/blob/master/lua/99/ops/make-prompt.lua): prompt composer · Combines operation inputs into the final request prompt. · `lua/99/ops/make-prompt.lua`
- [Search](https://github.com/theprimeagen/99/blob/master/lua/99/ops/search.lua): analysis flow · Orchestrates project-wide AI analysis and navigation results. · `lua/99/ops/search.lua`
- [Ops hub](https://github.com/theprimeagen/99/blob/master/lua/99/ops/init.lua): workflow dispatch · Coordinates operation entrypoints such as visual edits and other flows. · `lua/99/ops/init.lua`
- [Request status](https://github.com/theprimeagen/99/blob/master/lua/99/ops/request_status.lua): lifecycle state · Tracks active requests and their visible status. · `lua/99/ops/request_status.lua`

### Support

Logging, docs, queries, tests, and automation around the core.

- [Logger](https://github.com/theprimeagen/99/blob/master/lua/99/logger/logger.lua): observability · Structured logging for provider calls, prompts, and lifecycle events. · `lua/99/logger/logger.lua`
- [Editor LSP](https://github.com/theprimeagen/99/blob/master/lua/99/editor/lsp.lua): editor integration · Neovim editor/LSP helpers used by workflows and context discovery. · `lua/99/editor/lsp.lua`

## Connections

- 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.
