Skip to content

specifiedcodes/ContextforAIcoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

ContextforAIcoder

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) and PROJECT_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).

Directory Structure

ContextforAIcoder/
├── context/
│   ├── PROJECT_CONTEXT.template.json
│   ├── cursorrules.template.json
│   └── watchers/
│       ├── watch_changes.py
│       └── update_embeddings.py
├── README.md
├── .gitignore
└── ...

What’s Inside

  • PROJECT_CONTEXT.template.json
    A base JSON template for storing high-level project metadata (name, description, features, tech stack, etc.). Copy or rename it to PROJECT_CONTEXT.json in your actual project.
  • cursorrules.template.json
    A template defining code documentation/style rules for AI tools. Rename/copy to .cursorrules (or cursorrules.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 calls update_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.

Requirements

  1. Python 3.8+
    For running the watchers and embedding scripts.
  2. 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 with HuggingFaceEmbeddings if you prefer local embeddings.)
  3. Git (optional but recommended)
    If you want to use Git hooks or submodule approach.

Setup

  1. Clone this Repo
    git clone https://github.com/specifiedcodes/ContextforAIcoder.git
  2. (Optional) Add a .gitignore
    Make sure your local embeddings directory (.chroma/ or db/) is ignored to avoid committing large files.

Usage

A. Embedding Code & Docs

  1. 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
    
  2. 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 the TARGET_EXTENSIONS list inside watch_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")).


B. Integrating with Your Actual Project

You have two main approaches to bring these meta-tools into your real project:

  1. Submodule Approach
    git submodule add https://github.com/specifiedcodes/ContextforAIcoder.git context
    Now you have a context/ folder with all scripts. You can rename or move the .template files and start using them.
  2. Manual Copy
    Simply copy context/ into your project.
    You lose the direct link to updates in ContextforAIcoder, but it may be simpler if you prefer a one-off integration.

C. Setting Up .cursorrules and PROJECT_CONTEXT.json

  1. Rename cursorrules.template.json.cursorrules (or cursorrules.json) in your project’s root.
  2. Fill PROJECT_CONTEXT.template.jsonPROJECT_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"
      ]
      ...
    }
    
  3. Edit the contents to reflect your code style. For example, if you prefer JSDoc over XML doc comments, change the rules in .cursorrules.

D. Referencing .cursorrules in Cursor or Other AI Tools

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.


E. Using the Vector Database

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.


Advanced Tips & Customizations

  • Chunking Large Files
    If you have large source files or docs, you might want to chunk them. Within update_embeddings.py, consider splitting content into segments before embedding.
  • Auth/Keys
    If you’re using OpenAIEmbeddings, you need your OPENAI_API_KEY in the environment, for example:
    export OPENAI_API_KEY="sk-..."
    
  • Alternative Embeddings
    If you prefer offline embeddings, install sentence-transformers or HuggingFaceEmbeddings instead of OpenAIEmbeddings.
  • Performance
    Watchdog-based watchers can be resource-intensive on large projects. Use the Git hook approach for a more lightweight option.
  • Git Hooks
    Example: a pre-commit hook that calls update_embeddings.py for staged files only, ensuring all changed code is re-embedded before commits.

Recommended Workflow

  1. Create/Copy .cursorrules and PROJECT_CONTEXT.json into each project.
  2. Run python watch_changes.py to keep embeddings fresh automatically.
  3. Use your AI tool (Cursor, ChatGPT, local LLM) to reference .cursorrules for consistent doc/comment style.
  4. (Optional) Build or run a query script to do semantic searches over your code.
  5. Iterate on your .cursorrules and PROJECT_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.

About

This repository provides a “Meta/Context” system for advanced AI-driven development

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages