Persistent structural context infrastructure for AI coding agents.
Project description
Synap 🧠
The Deterministic Context Injector for AI Coding Agents.
Synap is NOT a RAG system. It is a strict, deterministic background daemon that mirrors your Git state and proactively pushes exact contextual boundaries to AI coding agents via the Model Context Protocol (MCP). Agents do not query Synap—Synap injects reality into Agents.
🏛️ Philosophy & Vision
- DETERMINISTIC FIRST: If the agent sees it, it exists exactly as shown in the local filesystem.
- PUSH, NOT PULL: Agents are terrible at querying for what they don't know exists. Synap bounds their context upfront.
- NOTHING HAPPENS SILENTLY: Every action, decision, and LLM call is tracked, costed, and logged.
- LOCAL ONLY: Your code never leaves your machine unless you explicitly configure a remote LLM. All state is kept in
.synap/synap.db. - MIRROR GIT EXACTLY: Synap's state machine is perfectly synced to
HEAD. If you switch branches, your agent's memory switches branches instantly.
⚡ Performance Architecture (v1.1.0)
Synap is built on the Git-Snapshot Paradigm to guarantee sub-100ms response times for everyday agent workflows:
- Two separate code paths: First-run indexing uses process-pool parallel parsing (
ProcessPoolExecutor) to build the initial codebase structure, while subsequent indexing uses a Git delta change detector (git diff-tree) to process only changed files. (Reason: Avoids full filesystem scans on every run). - No filesystem scan / file hashing on incremental runs: Synap uses Git blob OIDs to detect changed files. (Reason: Git already hashes everything, making filesystem reads redundant).
- Decoupled non-deterministic LLM pipeline: Structural parsing (deterministic, fast) completes immediately and enqueues wiki generation (non-deterministic, slow) to a background worker, while lazy caching fallback handles CLI/API wiki requests. (Reason: Never block structural indexing or CLI commands on LLM API response latency).
- SQLite optimizations: SQLite writes are grouped into a single transaction per batch (Reason: Avoids disk sync overhead per row). SQLite FTS5 index matches symbols in sub-milliseconds (Reason: Eliminates slow wildcard
LIKEtable scans). Pre-computed dot-separatedmodule_keycolumns allow O(1) module resolution (Reason: Prevents suffix-matching scans).
🏗️ High-Level Architecture (HLD)
Synap bridges the gap between your local file system, Git history, and the LLM via a 3-layer indexing strategy.
graph TD
subgraph Local Repository
FS[File System]
Git[Git History]
end
subgraph Synap Daemon
I[Indexer Engine]
DB[(SQLite synap.db)]
W[Wiki Engine .synap/wiki/]
M[Context Injector memory.py]
end
subgraph IDE / AI
MCP[MCP Server]
Agent[AI Coding Agent]
end
FS -->|Change Events| I
Git -->|Branch/Revert Events| I
I -->|L1 Structural| DB
I -->|L2 Semantic| W
I -->|L3 Behavioral| DB
DB --> M
W --> M
M -->|Injection Payload| MCP
MCP <-->|Read/Write Tools| Agent
🧩 The 3 Layers of Context
Synap provides three distinct layers of context to completely ground the agent:
1. L1: Structural (The Truth)
Deterministic mapping of code architecture using Tree-sitter.
- Fast, 100% accurate symbol extraction.
- Graph edges mapping
Imports,Inherits,Calls, andReferences. - Primary Key:
sha256(path + content_hash)to completely eliminate edge-case collisions.
2. L2: Semantic (The "Why")
Hierarchical generated documentation stored locally as Markdown files (.synap/wiki/).
- File Level: What does this file do?
- Module Level: How do these files relate?
- Project Level:
overview.mdandarchitecture.md.
3. L3: Behavioral (Agent Memory)
Synap tracks the history of agent actions so the AI doesn't repeat past mistakes.
- Checkpoints: The active task the agent is performing (
synap checkpoint). - Decisions: Architecture decisions logged by the agent.
- Lessons: Generated automatically when a developer runs
git reverton an agent's commit!
🔄 Low-Level Data Flows (LLD)
Git Mirroring Flow
Synap's daemon watches the Git repository. The state of the repository completely drives the context.
sequenceDiagram
participant Dev as Developer
participant Git as Git Repo
participant Daemon as Synap Daemon
participant DB as SQLite DB
Dev->>Git: git checkout feature-branch
Git-->>Daemon: Branch Switch Event
Daemon->>DB: Swap active context immediately
Dev->>Git: git revert <agent-commit>
Git-->>Daemon: Revert Detected (20-ancestor check)
Daemon->>DB: Log Pending Lesson (What failed?)
Daemon->>Dev: Prompt interactive review of failure
Context Injection Flow
When an Agent starts a task, it receives a strict, pre-packaged header injection.
sequenceDiagram
participant Agent
participant MCP as MCP Server
participant Memory as Context Injector
participant DB as SQLite DB
Agent->>MCP: Trigger Tool / Start Task
MCP->>Memory: build_injection_context()
Memory->>DB: Fetch Active Branch & Checkpoint
Memory->>DB: Fetch Approved Lessons
Memory->>DB: Check for Dirty Git Tree (Uncommitted changes)
Memory-->>MCP: Formatted Context Header
MCP-->>Agent: Proactive Context Grounding
🚀 Quick Start
1. Installation
Install the Synap CLI via pip or uv:
pip install synap-git
# or using uv:
uv tool install synap-git
2. Setup & Initialize
Interactive onboarding to set up your LLM providers (keys stored securely in your OS keyring).
synap setup .
Initialize the repo (Use --skip-llm to run in pure structural Mode A):
synap init .
3. Start the Daemon
Run the background watcher to keep Synap perfectly synced with Git:
synap start .
4. Connect to IDE
Start the MCP server to expose Synap to your AI Agent (Cursor, Windsurf, etc.):
synap mcp start .
💻 CLI Command Reference
Synap uses a powerful, strict CLI interface. Every destructive action prompts for approval.
Core Lifecycle
synap init .: Perform Pass 1 and Pass 2 indexing.synap start .: Launch the background polling daemon.synap status .: View active branch, indexed symbols, daemon state, and memory metrics.synap rollback .: Rollback active state to a previous commit.synap recover .: Recover from a corrupted database state.synap run .: Run all Synap services (Daemon, MCP, UI) concurrently.
L3 Memory Management
synap memory status .: View counts of approved, pending, and expired lessons.synap memory prune .: Prune expired rules and cleanup memory.synap memory verify .: Detect dangling file references in active memory.synap lessons review .: Interactively review and Approve/Edit/Reject pending lessons.synap lessons approve <id> .: Approve a pending revert lesson to activate it.synap lessons reject <id> .: Reject and discard a pending lesson.synap checkpoint create . --doing "...": Save the current context state.synap checkpoint list .: List all checkpoints for the active branch in a table.synap checkpoint restore <id> .: Show details of a checkpoint (or "latest").
Developer Tools
synap wiki list .: List all generated wiki documentation files.synap wiki show <filepath> .: Render a specific wiki markdown page to the console.synap usage show .: Display detailed aggregated LLM token usage.synap usage clear .: Purge all LLM call history.synap doctor .: Validate SQLite integrity, Tree-sitter, tokenizers, LLM providers, and daemon heartbeat.synap mcp verify .: Verify MCP protocol, tool schemas, and contract stability.
🤝 Contributing
Synap is built on the philosophy that AI tools must be transparent and controllable. If you're contributing:
- Do not introduce implicit RAG features.
- Adhere to the
SYNAP_BUILD_SPEC.mdstrictly. - Ensure all states are stored exclusively in
synap.dbor.synap/wiki/.
License: Apache 2.0 ](LICENSE.md)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file synap_git-1.1.1.tar.gz.
File metadata
- Download URL: synap_git-1.1.1.tar.gz
- Upload date:
- Size: 75.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1bdd72983aa9405c636b22d67dec376767118f549bfa185db1d5d7fa9973dece
|
|
| MD5 |
635c9e90d3b4d6dff08ba69a14f4216a
|
|
| BLAKE2b-256 |
ec7649f3ed8839ec685ea7c8897cc3d4a0f871b7a6212e9731699985f2967135
|
Provenance
The following attestation bundles were made for synap_git-1.1.1.tar.gz:
Publisher:
release.yml on saahilpal/synapse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
synap_git-1.1.1.tar.gz -
Subject digest:
1bdd72983aa9405c636b22d67dec376767118f549bfa185db1d5d7fa9973dece - Sigstore transparency entry: 1651315832
- Sigstore integration time:
-
Permalink:
saahilpal/synapse@7bab859e709bd3487d27fd94535496cccf6e1fa9 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/saahilpal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7bab859e709bd3487d27fd94535496cccf6e1fa9 -
Trigger Event:
push
-
Statement type:
File details
Details for the file synap_git-1.1.1-py3-none-any.whl.
File metadata
- Download URL: synap_git-1.1.1-py3-none-any.whl
- Upload date:
- Size: 85.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
231a8f762f54fc561bb8e44f6283ef9dc9981399f8b76834e64a4671ce7f49ed
|
|
| MD5 |
52742095c05c42bd43f184bfd5452eb6
|
|
| BLAKE2b-256 |
4717e380c880ac83d15998df927d893fcad5ce68b1d3ac6f0b0c53a8bf178e11
|
Provenance
The following attestation bundles were made for synap_git-1.1.1-py3-none-any.whl:
Publisher:
release.yml on saahilpal/synapse
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
synap_git-1.1.1-py3-none-any.whl -
Subject digest:
231a8f762f54fc561bb8e44f6283ef9dc9981399f8b76834e64a4671ce7f49ed - Sigstore transparency entry: 1651316094
- Sigstore integration time:
-
Permalink:
saahilpal/synapse@7bab859e709bd3487d27fd94535496cccf6e1fa9 -
Branch / Tag:
refs/tags/v1.1.1 - Owner: https://github.com/saahilpal
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7bab859e709bd3487d27fd94535496cccf6e1fa9 -
Trigger Event:
push
-
Statement type: