Skip to content

Commit 734353f

Browse files
authored
docs: update architecture and add AGENTS.md (#1546)
- Add AGENTS.md with detailed project overview, layout, and gotchas. - Revise CONTRIBUTING.md to clarify core, UI, features, and utilities. - Expand descriptions for each module and directory. - Improve structure for easier onboarding and contribution.
1 parent 0b3133f commit 734353f

2 files changed

Lines changed: 139 additions & 48 deletions

File tree

AGENTS.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# AGENTS.md
2+
3+
## Overview
4+
5+
Neovim plugin (pure Lua) providing GitHub Copilot Chat integration. Requires Neovim 0.10.0+, curl 8.0.0+, plenary.nvim.
6+
7+
## Commands
8+
9+
```bash
10+
# Run tests (headless Neovim + plenary test harness)
11+
make test
12+
13+
# Format check (what CI runs)
14+
stylua --check .
15+
```
16+
17+
`make test` runs `nvim --headless --clean -u ./scripts/test.lua`, which clones plenary.nvim into `.dependencies/` on first run, then executes all `tests/*_spec.lua` files via plenary's busted-style harness.
18+
19+
## Project layout
20+
21+
```
22+
plugin/CopilotChat.lua — Neovim plugin entry: commands, highlights, autocmds
23+
lua/CopilotChat/
24+
init.lua — Main module: setup(), ask(), open/close/toggle, save/load
25+
client.lua — Copilot API client (auth, streaming, tool calls)
26+
config.lua — Default configuration schema
27+
config/ — Sub-configs: functions, mappings, prompts, providers
28+
constants.lua — Shared constants (roles, etc.)
29+
completion.lua — Completion source
30+
functions.lua — Built-in functions/tools exposed to the LLM
31+
prompts.lua — Built-in prompt definitions
32+
resources.lua — Resource handling
33+
select.lua — Selection strategies (visual, buffer, diagnostics, git diff)
34+
tiktoken.lua — Token counting via native tiktoken lib
35+
health.lua — :checkhealth integration
36+
notify.lua — Notification utilities
37+
instructions/ — System prompt templates injected into LLM conversations (not agent guidance)
38+
ui/ — Chat window, overlay, spinner
39+
utils.lua — General utilities
40+
utils/ — Utility modules: class, curl, diff, files, orderedmap, stringbuffer
41+
queries/ — Treesitter queries for copilot-chat filetype
42+
tests/ — Plenary busted-style specs (*_spec.lua)
43+
scripts/
44+
test.lua — Test runner bootstrap (sets up plenary)
45+
minimal.lua — Minimal reproduction config
46+
doc/CopilotChat.txt — Auto-generated vimdoc (do NOT edit; generated from README by panvimdoc in CI)
47+
```
48+
49+
## Style and formatting
50+
51+
- **Lua formatter:** StyLua — 2-space indent, 120 column width, single quotes preferred, Unix line endings. Config in `.stylua.toml`.
52+
- **Pre-commit hooks:** Prettier (markdown/json/yaml) + StyLua (Lua). CI will fail if StyLua check fails.
53+
- **No linter** (no luacheck/selene configured).
54+
- Type annotations use EmmyLua/LuaCATS `---@class`, `---@param`, `---@return` style.
55+
56+
## Testing
57+
58+
- Framework: plenary.nvim busted-style (`describe`, `it`, `before_each`, `after_each`, `assert`).
59+
- Test files live in `tests/` and must be named `*_spec.lua`.
60+
- CI runs tests against Neovim nightly with LuaJIT 2.1 and LuaRocks 3.12.2.
61+
- Tests are unit-level (class, diff, utils, orderedmap, stringbuffer, functions, init). No integration tests requiring Copilot auth.
62+
63+
## CI and releases
64+
65+
- CI (`ci.yml`): lint (StyLua) + test (plenary) on all PRs; vimdoc generation on main only.
66+
- Releases via release-please (`simple` type). Version tracked in `version.txt`.
67+
- `doc/CopilotChat.txt` is auto-committed by CI — do not edit manually.
68+
- `CHANGELOG.md` is managed by release-please — do not edit manually.
69+
70+
## Key gotchas
71+
72+
- The module is loaded as `require('CopilotChat')` (capital C's) — this matches the `lua/CopilotChat/` directory name. Case matters.
73+
- `init.lua` uses lazy self-initialization via `__index` metamethod — accessing any field triggers `setup()` if not already called.
74+
- `.dependencies/` is gitignored and auto-populated by the test runner (plenary clone).
75+
- `build/` is gitignored and holds downloaded tiktoken native libraries.

CONTRIBUTING.md

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -50,67 +50,83 @@ Go to the CopilotChat.nvim in your GitHub account, select your branch, and click
5050

5151
![structure.drawio](https://github.com/CopilotC-Nvim/CopilotChat.nvim/assets/5115805/e7517736-0152-47a3-8cb9-36a5dffcb6cc)
5252

53-
### Main components
53+
### Core
5454

55-
- [init.lua](/lua/CopilotChat/init.lua): This file initializes Copilot Chat
56-
plugin. It includes functions for appending to the chat window, showing help,
57-
completing, getting selection, opening and closing the chat window, asking
58-
questions to the Copilot model, resetting the chat window, enabling/disabling
59-
debug, and setting up the plugin.
55+
- [init.lua](/lua/CopilotChat/init.lua): Main module. Plugin initialization
56+
(`setup()`), chat lifecycle (`ask()`, `open()`, `close()`, `toggle()`,
57+
`reset()`), save/load, and sticky prompt processing.
6058

61-
- [config.lua](/lua/CopilotChat/config.lua): This file contains default
62-
configuration for Copilot Chat plugin.
59+
- [client.lua](/lua/CopilotChat/client.lua): Copilot API client. Handles
60+
authentication, model listing, streaming requests, and tool call execution.
6361

64-
- [copilot.lua](/lua/CopilotChat/copilot.lua): This file contains the core
65-
functionality of the Copilot. It includes functions for generating unique IDs,
66-
finding configuration paths, authenticating, asking questions to the Copilot,
67-
generating embeddings, and managing the running job.
62+
- [config.lua](/lua/CopilotChat/config.lua): Default configuration schema.
6863

69-
- [chat.lua](/lua/CopilotChat/chat.lua): This file manages the chat window. It
70-
includes functions for creating, validating, appending to, clearing, opening,
71-
closing, and focusing on the chat window.
64+
- [config/](/lua/CopilotChat/config/): Sub-configs for
65+
[functions](/lua/CopilotChat/config/functions.lua),
66+
[mappings](/lua/CopilotChat/config/mappings.lua),
67+
[prompts](/lua/CopilotChat/config/prompts.lua), and
68+
[providers](/lua/CopilotChat/config/providers.lua).
7269

73-
- [diff.lua](/lua/CopilotChat/diff.lua): This file manages the diff window. It
74-
includes functions for creating, validating, showing, and restoring the diff
75-
window.
70+
- [constants.lua](/lua/CopilotChat/constants.lua): Shared constants (plugin
71+
name, roles).
7672

77-
- [select.lua](/lua/CopilotChat/select.lua): This file contains functions for
78-
selecting and processing different types of data such as visual selection,
79-
unnamed register, whole buffer, current line, diagnostics, and git diff.
73+
### Chat and UI
8074

81-
- [context.lua](/lua/CopilotChat/context.lua): This file is responsible for
82-
building an outline for a buffer and finding items for a query. It uses spatial
83-
distance and relatedness to rank data.
75+
- [ui/chat.lua](/lua/CopilotChat/ui/chat.lua): Chat window management.
76+
Creating, appending to, clearing, opening, closing, and focusing the chat
77+
window. Handles fold expressions and section parsing.
8478

85-
- [actions.lua](/lua/CopilotChat/actions.lua): This file manages the actions
86-
that can be performed. It includes functions for getting help actions, prompt
87-
actions, and picking an action from a list of actions using `vim.ui.select`.
79+
- [ui/overlay.lua](/lua/CopilotChat/ui/overlay.lua): Overlay buffer used for
80+
displaying diff previews and other transient content.
8881

89-
- [tiktoken.lua](/lua/CopilotChat/tiktoken.lua): This file manages integration
90-
with Tiktoken library and is used for counting tokens. It includes functions
91-
for setting up Tiktoken, checking its availability, encoding prompts, and
92-
counting prompts.
82+
- [ui/spinner.lua](/lua/CopilotChat/ui/spinner.lua): Loading spinner indicator
83+
for the chat window.
9384

94-
- [health.lua](/lua/CopilotChat/health.lua): This file checks the health of the
95-
plugin by checking if commands exist, checking if Lua libraries are installed,
96-
and checking if a Treesitter parsers are available.
85+
### Features
9786

98-
- [spinner.lua](/lua/CopilotChat/spinner.lua): This file manages a spinner that
99-
is used for indicating loading status in chat window.
87+
- [prompts.lua](/lua/CopilotChat/prompts.lua): Prompt resolution, custom
88+
instruction loading, system prompt building, and sticky/resource/tool
89+
parsing from user input.
10090

101-
- [utils.lua](/lua/CopilotChat/utils.lua): This file contains utility functions
102-
for creating classes, getting the log file path, checking if the current
103-
version of Neovim is stable, and joining multiple async functions.
91+
- [functions.lua](/lua/CopilotChat/functions.lua): Built-in functions/tools
92+
exposed to the LLM (e.g., file editing, searching).
10493

105-
- [debuginfo.lua](/lua/CopilotChat/debuginfo.lua): This file is used for
106-
creating `:CopilotChatDebugInfo` command.
94+
- [resources.lua](/lua/CopilotChat/resources.lua): Resource handling for file
95+
and URL content retrieval with caching.
10796

108-
### Integrations
97+
- [completion.lua](/lua/CopilotChat/completion.lua): Completion source for the
98+
chat window (`@tools`, `/prompts`, `#resources`, `$models`).
10999

110-
- [telescope.lua](/lua/CopilotChat/integrations/telescope.lua): This file
111-
integrates the Telescope plugin with CopilotChat. It includes a function for
112-
picking an action from a list of actions.
100+
- [select.lua](/lua/CopilotChat/select.lua): Selection strategies for providing
101+
context (visual selection, buffer, diagnostics, git diff, etc.).
113102

114-
- [fzflua.lua](/lua/CopilotChat/integrations/fzflua.lua): This file integrates
115-
the fzf-lua plugin with CopilotChat. It includes a function for picking an
116-
action from a list of actions.
103+
- [tiktoken.lua](/lua/CopilotChat/tiktoken.lua): Token counting via native
104+
tiktoken library.
105+
106+
- [instructions/](/lua/CopilotChat/instructions/): System prompt templates
107+
injected into LLM conversations (edit formats, tool use instructions, custom
108+
instructions wrapper).
109+
110+
### Utilities
111+
112+
- [utils.lua](/lua/CopilotChat/utils.lua): General utility functions.
113+
114+
- [utils/](/lua/CopilotChat/utils/): Utility modules —
115+
[class.lua](/lua/CopilotChat/utils/class.lua) (OOP helper),
116+
[curl.lua](/lua/CopilotChat/utils/curl.lua) (HTTP requests),
117+
[diff.lua](/lua/CopilotChat/utils/diff.lua) (unified diff parsing and
118+
application),
119+
[files.lua](/lua/CopilotChat/utils/files.lua) (file I/O and filetype
120+
detection),
121+
[orderedmap.lua](/lua/CopilotChat/utils/orderedmap.lua) (insertion-ordered
122+
map),
123+
[stringbuffer.lua](/lua/CopilotChat/utils/stringbuffer.lua) (efficient string
124+
concatenation).
125+
126+
### Other
127+
128+
- [health.lua](/lua/CopilotChat/health.lua): `:checkhealth` integration.
129+
Verifies commands, libraries, and Treesitter parsers.
130+
131+
- [notify.lua](/lua/CopilotChat/notify.lua): Pub/sub notification system for
132+
status and message events.

0 commit comments

Comments
 (0)