Keep your AI documentation fresh and in sync with code changes.
π¦ npm package: ai-contextor
β Star us on GitHub: driule/ai-contextor
π Support this project: GitHub Sponsors
Check documentation freshness for AI assistant projects. Automatically detects when documentation needs updates after code changes. Non-intrusive, git-aware, and highly configurable.
Install as a development dependency:
npm install --save-dev ai-contextorOr use it directly with npx (no installation needed):
npx ai-contextorGenerate initial documentation structure for your project:
npx contextor initThis command will:
- π Analyze your project structure
- π Detect project type (frontend, backend, fullstack, library, etc.)
- π οΈ Identify frameworks and technologies
- π Create
.ai/INIT.mdwith project context for AI assistants
Example output:
π Analyzing project structure...
β
Documentation initialized!
π Created: .ai/INIT.md
π Project Type: frontend
π οΈ Frameworks: React, Next.js
π» Languages: TypeScript, JavaScript, CSS
π‘ Review and customize .ai/INIT.md as needed.
Create .contextor.config.js in your project root to customize behavior:
module.exports = {
// Documentation directory
docsDir: ".ai",
// Source directories to monitor
sourceDirs: ["src"],
// Mapping: source files β documentation files
mappings: {
"src/app.ts": [".ai/architecture/system-overview.md"],
"src/services/**/*.ts": [".ai/architecture/components.md"],
},
// Cache file location (default: .ai/docs-check-cache.json)
cacheFile: ".ai/docs-check-cache.json",
// Check settings
check: {
lastUpdated: true, // Check "Last Updated" dates
version: true, // Check version numbers
links: true, // Check broken links
structure: true, // Check required sections
},
};Run the checker to verify documentation freshness:
# Basic check
npx contextor
# Force check (ignore cache)
npx contextor --force
# Quiet mode (minimal output)
npx contextor --quietUse the task system for managing development documentation:
# 1. Create a new task
npx contextor task:new "Add user authentication"
# 2. Develop and document in .ai/dev/task-0/ folder
# - Edit requirements.md
# - Add notes to notes.md
# - Document implementation in implementation.md
# 3. Generate documentation drafts
npx contextor 0
# 4. AI assistant reviews and improves drafts
# - Review .ai/dev/task-0/doc-integration-*.md files
# - Follow instructions in DOC-INTEGRATION.md
# 5. Integrate improved documentation
npx contextor 0 --integrate
# 6. Commit documentation updates
git add .ai/
git commit -m "Update documentation for user authentication"- β Smart Project Analysis - Automatically detects project type and tech stack
- β
Documentation Initialization - Generates
.ai/INIT.mdwith project context - β Development Task System - Manage temporary task documentation with integration workflow
- β Freshness Checking - Detects outdated documentation
- β Git Integration - Only checks when code changes
- β Link Validation - Checks for broken internal links
- β Structure Validation - Ensures required sections exist
- β Smart Caching - Avoids redundant checks
- β Safe Defaults - Won't overwrite existing documentation unless forced
- β Configurable - Works with any project structure
The init command analyzes your project and creates a comprehensive INIT.md file:
npx contextor initWhat it does:
- Scans project structure (directories, files, dependencies)
- Detects project type (frontend/backend/fullstack/library/monorepo)
- Identifies frameworks (React, Vue, Express, NestJS, etc.)
- Detects build tools (Webpack, Vite, etc.)
- Identifies test frameworks (Jest, Vitest, Cypress, etc.)
- Generates
.ai/INIT.mdwith:- Project overview and type
- Technology stack
- Project structure explanation
- Development workflow
- Documentation guidelines
- AI assistant instructions
Run the checker to ensure documentation stays up-to-date:
# Standard check
npx contextor
# Force check (bypass cache)
npx contextor --force
npx contextor -f
# Quiet mode
npx contextor --quiet
npx contextor -qWhat it checks:
- Whether source files were modified after documentation
- Missing "Last Updated" dates
- Broken internal links
- Required documentation sections
- Documentation structure compliance
Manage temporary development documentation with the task system:
1. Create a new task:
npx contextor task:new "Add user authentication"This creates .ai/dev/task-0/ with:
README.md- Task overview and statusrequirements.md- Detailed requirements templatenotes.md- Development notes templateimplementation.md- Implementation details template
2. Generate documentation drafts:
# After committing code changes
npx contextor 0This generates:
doc-integration-*.md- Draft documentation filesDOC-INTEGRATION.md- Instructions for AI assistant
3. Integrate improved drafts:
# After AI assistant improves drafts
npx contextor 0 --integrateThis integrates the improved drafts into main documentation (.ai/ directory).
Task workflow:
- Create task β Develop β Document in task folder
- Commit code β Generate drafts
- AI assistant improves drafts
- Integrate β Commit documentation
Copy .contextor.config.js.example to .contextor.config.js and customize:
cp .contextor.config.js.example .contextor.config.jsKey configuration options:
docsDir- Documentation directory (default:.ai)sourceDirs- Directories to monitor for changesmappings- Map source files to documentation filescacheFile- Cache file locationcheck.*- Enable/disable specific checks
# 1. Install
npm install --save-dev ai-contextor
# 2. Initialize documentation
npx contextor init
# 3. Review and customize .ai/INIT.md
# 4. Add to package.json scripts
# "scripts": {
# "docs:check": "contextor"
# }
# 5. Run checks
npm run docs:check# 1. Initialize documentation
npx contextor init
# 2. Configure mappings in .contextor.config.js
# 3. Create documentation files in .ai/ directory
# 4. Run checks regularly
npx contextorAdd to your CI pipeline:
# GitHub Actions example
- name: Check documentation freshness
run: npx contextorAfter initialization, your project will have:
your-project/
βββ .ai/
β βββ INIT.md # Generated project context
β βββ README.md # Documentation framework overview
β βββ architecture/ # Architecture documentation
β βββ api/ # API documentation
β βββ examples/ # Usage examples
β βββ dev/ # Development tasks (gitignored)
β β βββ README.md # Task system documentation
β β βββ task-N/ # Individual task directories
β βββ docs-check-cache.json # Cache file (gitignored)
βββ .contextor.config.js # Configuration (optional)
βββ ...
Note: The .ai/dev/ directory is gitignored and contains temporary task documentation.
| Command | Description |
|---|---|
npx contextor |
Check documentation freshness (default) |
npx contextor init |
Initialize documentation structure |
npx contextor init --force |
Initialize and overwrite existing INIT.md |
npx contextor task:new "description" |
Create a new development task directory |
npx contextor <task-list> |
Generate documentation drafts for tasks |
npx contextor <task-list> --integrate |
Integrate improved drafts into main docs |
npx contextor --help |
Show help message |
npx contextor --version |
Show version number |
| Option | Description |
|---|---|
--force, -f |
Force mode (overwrite INIT.md or ignore cache) |
--quiet, -q |
Quiet mode (minimal output) |
# Initialize documentation
npx contextor init
# Initialize and overwrite existing INIT.md
npx contextor init --force
# Create a new task
npx contextor task:new "Add user authentication"
# Generate drafts for task-0
npx contextor 0
# or
npx contextor task-0
# Generate drafts for multiple tasks
npx contextor 0,1,2
# or
npx contextor task-0,task-1,task-2
# Integrate improved drafts
npx contextor 0 --integrate
# Check documentation freshness
npx contextor
# Force check (ignore cache)
npx contextor --force
# Quiet mode
npx contextor --quietDocumentation files in .ai/ directory should follow this structure:
# Document Title
**Last Updated**: YYYY-MM-DD
**Version**: 1.0.0
## Overview
Brief description...
## Details
Main content...
## π Related Documentation
- [Link to related doc](./other-doc.md)Contributions welcome! Please read our Contributing Guidelines first.
Ways to contribute:
- π Report bugs
- π‘ Suggest new features
- π Improve documentation
- π§ Submit pull requests
- β Star the repository
This project is open source and free to use. If you find it helpful, please consider:
- β Starring the repository on GitHub
- π Reporting bugs and issues
- π¬ Sharing with your team and community
- π Sponsoring the project to support continued development
Support this project through GitHub Sponsors. Your sponsorship helps:
- π Maintain and improve the project
- π Fix bugs faster
- β¨ Add new features
- π Create better documentation
Sponsorship Tiers:
- π€ Assistant ($5/month) - Thank you! Your name in README supporters list
- π Navigator ($15/month) - Priority support + your name in README
- β‘ Architect ($50/month) - All above + feature requests priority
- π Context Master ($200/month) - All above + custom features consultation
Note: GitHub Sponsors is free - GitHub doesn't take any fees for personal accounts!
- πΌ Hire me for consulting or custom development
- π§ Contact: GitHub Profile
MIT Β© Andrius
Current version: 0.5.4
Status: π§ Beta - Ready for use, but still in active development
- β¨ Safe init behavior - INIT.md is now skipped if exists (prevents overwriting custom docs)
- β¨ --force flag - Allows overwriting INIT.md when needed
- π§ Refactored generator - Improved code maintainability and extensibility
- π Task system - Complete development task workflow with draft generation and integration
- Unit tests and test coverage
- CI/CD pipeline
- TypeScript definitions
- More project type templates
- Enhanced error messages