Skip to content

feat: load and parse markdown role files as roles#201

Open
Konfekt wants to merge 4 commits into
madox2:mainfrom
Konfekt:roles
Open

feat: load and parse markdown role files as roles#201
Konfekt wants to merge 4 commits into
madox2:mainfrom
Konfekt:roles

Conversation

@Konfekt

@Konfekt Konfekt commented Feb 26, 2026

Copy link
Copy Markdown
Contributor

In case the config_file parameter happens to be a folder, use one markdown file per role. As these can get long, helps keeping everything in place

@madox2

madox2 commented Feb 27, 2026

Copy link
Copy Markdown
Owner

Hi, thanks for the contribution! I think the idea is good. Rather than introducing new concept and markdown file syntax, it could use existing aichat file/syntax. Then it would be easy to play around in the chat and make a role out of it. It would also be easier to maintain as the aichat file parsing logic is already implemented and can be reused.

Implemented:

- Added g:vim_ai_roles_config_path support with fallback to
  g:vim_ai_roles_config_file in loader logic: utils.py (./py/utils.py#L452), utils.py (./py/utils.py#L470)
- Directory behavior updated:
    - read all *.ini files in lexicographical order (merged like one ini)
    - keep current markdown parsing for *.md/*.markdown
    - applied in utils.py (./py/
      utils.py#L465)
- Renamed default config variable to _path while keeping _file backward-
  compatible:
    - defaults/compat in vim_ai_config.vim (./autoload/vim_ai_config.vim#L154)
    - :AIUtilRolesOpen now prefers _path with _file fallback in vim_ai.vim (./autoload/vim_ai.vim#L468)
- Docs updated to document _path usage and note _file compatibility:
    - README.md (./README.md#L145)
    - vim-ai.txt (./doc/vim-ai.txt#L274)
    - roles-example.ini (./roles-
      example.ini#L3)

Regression tests added/updated:

- Mixed directory coverage (*.ini + *.md) and _path precedence:
    - roles_test.py (./tests/
      roles_test.py#L54)
    - context_test.py (./tests/
      context_test.py#L299)
    - test fixtures: 01-base.ini (./
      tests/resources/roles-mixed/01-base.ini), 02-override.ini (./tests/resources/roles-mixed/02-
      override.ini), mixed-md-role.md (./tests/resources/roles-mixed/mixed-md-role.md)
- Mock updated for new global key: tests/mocks/vim.py (./tests/mocks/vim.py#L11)
@Konfekt

Konfekt commented Feb 28, 2026

Copy link
Copy Markdown
Contributor Author

Last commit addresses this, now merging all *.ini files and using _path instead of _file to reflect the value of a directory, though keeping the latter for backward compatibility. There's still the possiblity to read a markdown file though for prompts, as this format has become a defacto standard. I hope that's fine

@madox2

madox2 commented Mar 6, 2026

Copy link
Copy Markdown
Owner

I meant something else, having .aichat instead of .md, but nevermind, I think you are right and md files are better for this job.

@madox2

madox2 commented Mar 6, 2026

Copy link
Copy Markdown
Owner

One thing concerns me - if I had a big collection of potentially big md files, this way it would need to open and parse every single one during vim completion (using tab key). That might cause some performance issues.

It could be improved by caching the roles, but I would like to avoid caching if possible.

The other solution could be adding some naming convention to the md files, for example:

basic_role.md
image_role.image.md
chat_only_role.chat.md

This way it would only need to list directory for markdown files and load ini files to complete roles. It would be also easier to parse header (don't need to assume different command types). It won't be possible to provide different config for chat/complete/edit command types in a single md file but I would accept that limitation.

@Konfekt

Konfekt commented Mar 7, 2026

Copy link
Copy Markdown
Contributor Author

I wonder at which point the content of each file hat to be parsed? For :AIChat / the file names seem sufficient?

@madox2

madox2 commented Mar 7, 2026

Copy link
Copy Markdown
Owner

I would say for completion it needs to load content of ini files and filenames of md files. When running actual role it needs to load ini files and a particular md file if exists

@Konfekt

Konfekt commented Mar 8, 2026

Copy link
Copy Markdown
Contributor Author

One thing concerns me - if I had a big collection of potentially big md files, this way it would need to open and parse every single one during vim completion

So it would not have to for completion, and the concern is luckily unwarranted?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants