# Git Tools for Cognitive Modeling
---
title: Git Tools for Cognitive Modeling
type: tool-documentation
status: stable
created: 2024-07-25
tags:
- git
- version-control
- knowledge-management
- collaboration
- cognitive-modeling
semantic_relations:
- type: implements
links: [[git_workflow]]
- type: relates
links:
- [[obsidian_usage]]
- [[cursor_integration]]
- [[knowledge_management]]
- [[collaboration_tools]]
- [[continuous_integration]]
---
## Overview
This document details specialized Git tools and configurations designed specifically for cognitive modeling projects, with a focus on maintaining synchronization between code implementation and knowledge base documentation. These tools handle the unique challenges of managing both traditional code repositories and Obsidian-based knowledge graphs within a unified Git workflow.
## Core Git Tools
### Knowledge-Code Synchronization Tools
#### KB-Code Linker (`kb-code-linker`)
Links knowledge base concepts directly to their implementations.
```bash
# Installation
pip install kb-code-linker
# Usage
kb-code-linker scan --knowledge-dir knowledge_base/ --code-dir src/
kb-code-linker report --format markdown > kb_code_links.md
kb-code-linker validate --strict
```
#### Implementation Gap Detector (`impl-gap`)
Identifies concepts documented in the knowledge base but missing in code implementation.
```bash
# Installation
pip install impl-gap
# Usage
impl-gap analyze --kb-path knowledge_base/cognitive/ --impl-path src/cognitive/
impl-gap report --format json > implementation_gaps.json
```
#### Documentation Gap Finder (`doc-gap`)
Identifies code implementations without corresponding knowledge base documentation.
```bash
# Usage
python scripts/doc_gap_finder.py --src-dir src/ --kb-dir knowledge_base/
```
### Git Extensions for Cognitive Projects
#### Cognitive Git Hooks
```bash
# Pre-commit hook for ensuring consistent knowledge-code links
#!/bin/sh
# .git/hooks/pre-commit
python scripts/kb_code_validator.py
if [ $? -ne 0 ]; then
echo "Knowledge base and code are not in sync. Run kb-code-linker sync before committing."
exit 1
fi
```
#### Specialized Git Commands
```bash
# Installation
git clone https://github.com/cognitive-modeling/git-cognitive.git
cd git-cognitive
pip install -e .
# Usage
git cognitive kb-update # Updates knowledge base entries based on code changes
git cognitive code-update # Updates code documentation based on knowledge base
git cognitive status # Shows knowledge-code synchronization status
```
## Integration Tools
### Obsidian Git Integration
#### Obsidian Git Plugin Configuration
```json
// .obsidian/plugins/obsidian-git/data.json (optimized for cognitive projects)
{
"autoSaveInterval": 15,
"autoPullInterval": 30,
"autoPullOnBoot": true,
"disablePopups": false,
"commitMessage": "kb: {{date}} - {{files}}",
"commitDateFormat": "YYYY-MM-DD HH:mm:ss",
"autoCommitMessage": "kb: auto-sync {{date}}",
"pushOnCommit": false,
"pullBeforePush": true,
"disablePrompts": false,
"listChangedFilesInMessageBody": true,
"showStatusBar": true,
"updateSubmodules": false,
"syncMethod": "merge",
"gitPath": "",
"customMessageFolder": "templates/commit-messages"
}
```
#### Knowledge Base Git Automation
```bash
# Installation
pip install kb-git-automator
# Usage
kb-git-automator watch --kb-dir knowledge_base/ --auto-commit
```
### Cursor AI Integration
#### Cursor Git Assistant Configuration
```json
// .cursorrules
{
"git": {
"suggestCommitMessages": true,
"suggestFileChanges": true,
"branchAssistance": true,
"prReviewAssistance": true,
"knowledgeBaseAwareness": true
},
"documentation": {
"suggestKnowledgeBaseLinks": true,
"validateKnowledgeReferences": true
}
}
```
#### AI-Assisted PR Templates
```markdown
<!-- .github/PULL_REQUEST_TEMPLATE/cognitive_feature.md -->
# Cognitive Feature PR
## Description
<!-- Describe the changes implemented in this PR -->
## Knowledge Base Changes
<!-- List any knowledge base files that were updated -->
## Related Concepts
<!-- Reference related concept documentation -->
- [ ] [[concept1]]
- [ ] [[concept2]]
## Implementation Details
<!-- Technical implementation details -->
## Testing
<!-- How was this change tested? -->
## AI Assistant Notes
<!-- Notes from Cursor AI assistant (if used) -->
```
## Visualization Tools
### Knowledge-Code Graph Visualizer
```bash
# Installation
pip install kb-code-graph
# Usage
kb-code-graph generate --kb-dir knowledge_base/ --code-dir src/ --output graph.html
```
Example Output:
```mermaid
graph TD
subgraph Knowledge Base
A[Active Inference] --> B[Belief Updating]
A --> C[Policy Selection]
end
subgraph Code Implementation
D[ActiveInferenceAgent] --> E[BeliefUpdater]
D --> F[PolicySelector]
end
A -.->|implements| D
B -.->|implements| E
C -.->|implements| F
```
### Git History Visualizer for Cognitive Projects
```bash
# Installation
pip install cognitive-git-viz
# Usage
cognitive-git-viz --repo-path . --output git_history.html
```
## Specialized Git Configurations
### Cognitive Project `.gitattributes`
```
# .gitattributes for cognitive modeling projects
*.md diff=markdown
*.py diff=python
*.ipynb diff=jupyter
knowledge_base/** merge=cognitive-knowledge-merger
src/models/** merge=cognitive-model-merger
# LFS configuration for research data
*.csv filter=lfs diff=lfs merge=lfs -text
*.npy filter=lfs diff=lfs merge=lfs -text
*.pt filter=lfs diff=lfs merge=lfs -text
*.pkl filter=lfs diff=lfs merge=lfs -text
```
### Custom Git Diff and Merge Tools
```bash
# .gitconfig additions for cognitive projects
[diff "markdown"]
textconv = pandoc --to=plain
prompt = false
[diff "jupyter"]
textconv = jupyter nbconvert --to python --stdout
prompt = false
[merge "cognitive-knowledge-merger"]
name = Cognitive Knowledge Base Merger
driver = python scripts/kb_merge_driver.py %O %A %B %P
[merge "cognitive-model-merger"]
name = Cognitive Model Merger
driver = python scripts/model_merge_driver.py %O %A %B %P
```
## Automation and CI Tools
### GitHub Actions for Cognitive Projects
```yaml
# .github/workflows/cognitive-sync-validation.yml
name: Knowledge-Code Sync Validation
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
jobs:
validate-sync:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.10'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install kb-code-linker impl-gap
- name: Validate knowledge-code synchronization
run: kb-code-linker validate --strict
- name: Check for implementation gaps
run: impl-gap analyze --kb-path knowledge_base/ --impl-path src/ --fail-on-gaps
- name: Generate knowledge graph visualization
run: |
pip install kb-code-graph
kb-code-graph generate --kb-dir knowledge_base/ --code-dir src/ --output artifacts/knowledge_graph.html
- name: Upload artifacts
uses: actions/upload-artifact@v3
with:
name: knowledge-artifacts
path: artifacts/
```
### Pre-commit Hooks Configuration
```yaml
# .pre-commit-config.yaml
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- id: check-yaml
- id: check-added-large-files
args: ['--maxkb=500']
- repo: https://github.com/cognitive-modeling/cognitive-hooks
rev: v1.2.0
hooks:
- id: knowledge-code-sync
files: '^(knowledge_base|src)/'
- id: obsidian-link-checker
files: '^knowledge_base/.*\.md