Readme.md was generated using OpenAI so if you see some errors please don’t get triggered!
IMP: you can also use it with your existing project just tell your ai code helper to make changes to your files as per .cursorrules and then you can manually decide which changes you want and this way watcher will be called and it will update vector database too for updated context which you can later reference with your ai code helper.
This repository provides a “Meta/Context” system for advanced AI-driven development. It includes:
- Templates for
.cursorrules
(AI code style/documentation rules) andPROJECT_CONTEXT.json
(project details). - Automation Scripts to watch for code changes and automatically update a local vector database (Chroma) with new embeddings, enabling semantic search via LangChain.
- Guidelines for integrating these meta-features with your IDE (e.g., Cursor), ChatGPT, or local Large Language Models (LLMs).
ContextforAIcoder/
├── context/
│ ├── PROJECT_CONTEXT.template.json
│ ├── cursorrules.template.json
│ └── watchers/
│ ├── watch_changes.py
│ └── update_embeddings.py
├── README.md
├── .gitignore
└── ...
-
PROJECT_CONTEXT.template.json
A base JSON template for storing high-level project metadata (name, description, features, tech stack, etc.). Copy or rename it toPROJECT_CONTEXT.json
in your actual project. -
cursorrules.template.json
A template defining code documentation/style rules for AI tools. Rename/copy to.cursorrules
(orcursorrules.json
) in your target project so your IDE/AI sees it. -
watch_changes.py
A Python script using Watchdog to monitor file changes in real time. Whenever a watched file changes, it callsupdate_embeddings.py
to re-embed that file. -
update_embeddings.py
A Python script that uses LangChain + Chroma to embed the contents of changed files into a local vector database. This enables semantic search or advanced AI workflows.
- Python 3.8+
For running the watchers and embedding scripts. - Pip Packages:
pip install watchdog langchain chromadb openai tiktoken
- Watchdog: For file system monitoring.
- LangChain: For embedding and searching documents.
- Chroma (in
chromadb
): Local vector store. - OpenAI / tiktoken: If using OpenAI embeddings.
- (You can swap out
OpenAIEmbeddings
withHuggingFaceEmbeddings
if you prefer local embeddings.)
- Git (optional but recommended)
If you want to use Git hooks or submodule approach.
-
Clone this Repo
git clone https://github.com/specifiedcodes/ContextforAIcoder.git
-
(Optional) Add a
.gitignore
Make sure your local embeddings directory (.chroma/
ordb/
) is ignored to avoid committing large files.
-
Run
update_embeddings.py
Directly
(In the default example, it tries to embed
["src/routes/user.js", "README.md"]
. Adapt it to your own file paths.)cd context/watchers python update_embeddings.py
-
Run the Watcher Script (
watch_changes.py
)
In
context/watchers/
:python watch_changes.py
This script will watch for changes in your project (by default the current directory) and automatically call
update_embeddings.py <filepath>
each time a relevant file changes.
Modify theTARGET_EXTENSIONS
list insidewatch_changes.py
to match the file types you want to embed (.js
,.py
,.cs
,.md
, etc.).
Where Are the Embeddings Saved?
By default, Chroma will create a local DB folder (often .chroma/
) in your working directory.
You can customize this in update_embeddings.py
(e.g., db = Chroma(collection_name="my-project", persist_directory="my_chroma_db")
).
You have two main approaches to bring these meta-tools into your real project:
- Submodule Approach
Now you have a
git submodule add https://github.com/specifiedcodes/ContextforAIcoder.git context
context/
folder with all scripts. You can rename or move the.template
files and start using them. - Manual Copy
Simply copycontext/
into your project.
You lose the direct link to updates inContextforAIcoder
, but it may be simpler if you prefer a one-off integration.
- Rename
cursorrules.template.json
→.cursorrules
(orcursorrules.json
) in your project’s root. - Fill
PROJECT_CONTEXT.template.json
→PROJECT_CONTEXT.json
with real details about your project:{ "project_name": "My Cool Finance App", "description": "A containerized Node.js + Next.js finance project", "features": [ "User auth", "Transaction management" ] ... }
- Edit the contents to reflect your code style. For example, if you prefer JSDoc over XML doc comments, change the rules in
.cursorrules
.
Cursor (or any AI IDE extension) doesn’t automatically parse .cursorrules
unless specifically supported.
At a minimum, open the .cursorrules
file in your editor and tell the AI, “Please follow the rules in .cursorrules
for doc/comments.”
Alternatively, you can include .cursorrules
content in your system or user prompt if you’re using ChatGPT, Bing Chat, or a local LLM environment.
Semantic Search or Q&A about your code:
from langchain.embeddings import OpenAIEmbeddings from langchain.vectorstores import Chroma
db = Chroma(collection_name="finance-project", persist_directory=".chroma") query = "Where is the transaction logic handled?" results = db.similarity_search(query) print(results)
This returns the top matching docs/snippets. You can pass those snippets to your AI to provide deeper context.
Advanced: Build a LangChain “retrieval-augmented” system that automatically injects relevant code docs into your AI prompts. This can be done by creating a pipeline or chain in Python that uses the Chroma store, queries your docs, and calls an LLM with the retrieved context.
- Chunking Large Files
If you have large source files or docs, you might want to chunk them. Withinupdate_embeddings.py
, consider splitting content into segments before embedding. - Auth/Keys
If you’re usingOpenAIEmbeddings
, you need yourOPENAI_API_KEY
in the environment, for example:export OPENAI_API_KEY="sk-..."
- Alternative Embeddings
If you prefer offline embeddings, installsentence-transformers
orHuggingFaceEmbeddings
instead ofOpenAIEmbeddings
. - Performance
Watchdog-based watchers can be resource-intensive on large projects. Use the Git hook approach for a more lightweight option. - Git Hooks
Example: apre-commit
hook that callsupdate_embeddings.py
for staged files only, ensuring all changed code is re-embedded before commits.
- Create/Copy
.cursorrules
andPROJECT_CONTEXT.json
into each project. - Run
python watch_changes.py
to keep embeddings fresh automatically. - Use your AI tool (Cursor, ChatGPT, local LLM) to reference
.cursorrules
for consistent doc/comment style. - (Optional) Build or run a query script to do semantic searches over your code.
- Iterate on your
.cursorrules
andPROJECT_CONTEXT.json
as your style rules or project features evolve.
Enjoy your fully integrated AI “Meta/Context” pipeline! This approach should help you maintain consistent documentation/styles and empower advanced semantic search or retrieval-augmented AI workflows across all your projects.