A minimal MVP that adds semantic analysis to Git by detecting logic changes in JavaScript functions using embeddings and cosine similarity.
vectorgit/
├── bin_vectorgit CLI entry point
├── cli.js Main command handler
├── parser.js AST parsing for JS functions
├── embedder.js Convert code to embeddings
├── comparator.js Cosine similarity calculation
├── store.js JSON-based storage
├── package.json Dependencies
├── .env.example API key template
└── demo_auth_v*.js Demo scenario files
npm installcp .env.example .env
# Edit .env and add your OPENROUTER_API_KEY from https://openrouter.ainode cli.js initCreates .vectorgit/ directory and sets up git hooks.
node cli.js baselineAnalyzes all JS files in the repo and stores baseline embeddings.
node cli.js reviewCompares current code against baseline and flags regressions.
Use this exact sequence to baseline the safe version and then detect the buggy version.
# 1) Put safe code in active demo file
cp demo_access_control_safe.js demo_access_control.js
# 2) Save baseline from safe code
node cli.js baseline demo_access_control.js
# 3) Replace with buggy code
cp demo_access_control_buggy.js demo_access_control.js
# 4) Run review on the same file path
node cli.js review demo_access_control.jsWindows PowerShell equivalent:
Copy-Item .\demo_access_control_safe.js .\demo_access_control.js -Force
node cli.js baseline demo_access_control.js
Copy-Item .\demo_access_control_buggy.js .\demo_access_control.js -Force
node cli.js review demo_access_control.jsCreate your own safe file and buggy file, then use the same path for baseline and review.
# Example files you create:
# auth_guard_safe.js
# auth_guard_buggy.js
# 1) Copy safe version to active file path
cp auth_guard_safe.js auth_guard.js
# 2) Baseline safe version
node cli.js baseline auth_guard.js
# 3) Replace active file with buggy version
cp auth_guard_buggy.js auth_guard.js
# 4) Check for regression
node cli.js review auth_guard.js
# or:
node cli.js commit auth_guard.jsImportant rule: baseline and review must run against the same target file path (for example auth_guard.js).
- Creates
.vectorgit/directory - Sets up pre-commit git hook
- Initializes empty embeddings baseline
- Finds all JavaScript files in repo
- Extracts functions using Babel AST parser
- Generates embeddings for each function
- Stores baseline for comparison
- Loads baseline embeddings
- Recomputes embeddings for current code
- Calculates cosine similarity
- Flags functions with distance > 0.3 as regressions
node cli.js initCopy v1 to active file:
cp demo_auth_v1.js auth.js
node cli.js baseline auth.jsOutput:
🔍 Analyzing repository for baseline embeddings...
Found 1 JavaScript files
Extracted 3 functions
Computing embeddings...
✓ Saved 3 baseline embeddings
cp demo_auth_v2.js auth.js
node cli.js review auth.jsOutput:
🔐 Running semantic check...
Computing embeddings...
[⚠️ ALERT] Semantic Regression Detected
File: auth.js
Function: validateUser
Change Score: 0.78
Severity: HIGH
File: auth.js
Function: hashPassword
Change Score: 0.62
Severity: HIGH
File: auth.js
Function: authenticateUser
Change Score: 0.55
Severity: HIGH
- Uses Babel parser to convert JS into AST
- Extracts function declarations, arrow functions, methods
- Preserves original code for embedding
- Sends code snippets to OpenRouter's
text-embedding-3-smallmodel - Receives 1536-dimensional vectors
- Stores embeddings with file hash + function name as key
- Computes cosine similarity between current and baseline
- Distance = 1 - similarity (0 = identical, 1 = different)
- Flags changes > 0.3 threshold
.vectorgit/embeddings.jsonstores baseline- Key format:
<file_hash>::<function_name>@<line_number> - Simple JSON structure for portability
| Distance | Severity | Action |
|---|---|---|
| < 0.30 | ✓ OK | Pass |
| 0.30-0.40 | MEDIUM | Warning |
| 0.40-0.60 | HIGH | Alert |
| > 0.60 | CRITICAL | Block |
OPENROUTER_API_KEY- Required for embeddings (get from https://openrouter.ai)
.vectorgit/node_modules/.git/dist/,build/
.js.jsx.ts.tsx
When initialized, VectorGit sets up a pre-commit hook that:
- Runs
vectorgit commitbefore commit - Blocks commit if regressions detected (exit code 1)
- Shows detailed report of changes
Using text-embedding-3-small:
- ~$0.02 per 1M tokens
- ~100 tokens per function on average
- Example: 100 functions ≈ $0.0002
- Single language (JavaScript only)
- Function-level granularity only
- No diff-based optimization (always full re-embed)
- No caching between runs
- Threshold is hardcoded (no config file)
- No support for private/vendor code filtering
To enhance beyond MVP:
- Multi-language support - Add parsers for Python, Go, Rust
- Smart diffing - Only embed changed functions
- Configuration - Add
.vectorgit.config.jsonfor thresholds - Database - Replace JSON with SQLite for large repos
- UI - Web dashboard to visualize regressions
- CI/CD - GitHub Actions integration
- Blame - Link regressions to specific commits
{
"status": "alert",
"message": "Semantic Regression Detected",
"regressions": [
{
"key": "abc12345::validateUser@10",
"distance": 0.78,
"file": "auth.js",
"name": "validateUser",
"severity": "HIGH"
}
]
}Built for Google Solutions 2026