synapse-pkg 2.0.0a6__tar.gz → 3.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. {synapse_pkg-2.0.0a6 → synapse_pkg-3.0.0}/LICENSE +2 -2
  2. synapse_pkg-3.0.0/PKG-INFO +310 -0
  3. synapse_pkg-3.0.0/README.md +295 -0
  4. synapse_pkg-3.0.0/pyproject.toml +31 -0
  5. synapse_pkg-3.0.0/synapse/__init__.py +3 -0
  6. synapse_pkg-3.0.0/synapse/analysis/__init__.py +1 -0
  7. synapse_pkg-3.0.0/synapse/analysis/dispatcher.py +98 -0
  8. synapse_pkg-3.0.0/synapse/analysis/js_analyzer.py +293 -0
  9. synapse_pkg-3.0.0/synapse/analysis/python_analyzer.py +244 -0
  10. synapse_pkg-3.0.0/synapse/analysis/ts_analyzer.py +373 -0
  11. synapse_pkg-3.0.0/synapse/cli.py +376 -0
  12. synapse_pkg-3.0.0/synapse/core.py +300 -0
  13. synapse_pkg-3.0.0/synapse/exclusions.py +99 -0
  14. synapse_pkg-3.0.0/synapse/export/__init__.py +1 -0
  15. synapse_pkg-3.0.0/synapse/export/exporter.py +130 -0
  16. synapse_pkg-3.0.0/synapse/git/__init__.py +1 -0
  17. synapse_pkg-3.0.0/synapse/git/ops.py +182 -0
  18. synapse_pkg-3.0.0/synapse/graph/__init__.py +1 -0
  19. synapse_pkg-3.0.0/synapse/graph/builder.py +362 -0
  20. synapse_pkg-3.0.0/synapse/index/__init__.py +1 -0
  21. synapse_pkg-3.0.0/synapse/index/store.py +497 -0
  22. synapse_pkg-3.0.0/synapse/models.py +116 -0
  23. synapse_pkg-3.0.0/synapse/parsing/__init__.py +1 -0
  24. synapse_pkg-3.0.0/synapse/parsing/parser.py +75 -0
  25. synapse_pkg-3.0.0/synapse/retrieval/__init__.py +1 -0
  26. synapse_pkg-3.0.0/synapse/retrieval/engine.py +360 -0
  27. synapse_pkg-3.0.0/synapse_pkg.egg-info/PKG-INFO +310 -0
  28. synapse_pkg-3.0.0/synapse_pkg.egg-info/SOURCES.txt +39 -0
  29. synapse_pkg-3.0.0/synapse_pkg.egg-info/requires.txt +4 -0
  30. synapse_pkg-3.0.0/tests/test_phase1.py +195 -0
  31. synapse_pkg-3.0.0/tests/test_phase2.py +525 -0
  32. synapse_pkg-3.0.0/tests/test_phase3.py +297 -0
  33. synapse_pkg-3.0.0/tests/test_phase4.py +352 -0
  34. synapse_pkg-3.0.0/tests/test_phase5.py +258 -0
  35. synapse_pkg-3.0.0/tests/test_phase6.py +213 -0
  36. synapse_pkg-3.0.0/tests/test_phase7.py +308 -0
  37. synapse_pkg-3.0.0/tests/test_phase8.py +268 -0
  38. synapse_pkg-2.0.0a6/PKG-INFO +0 -312
  39. synapse_pkg-2.0.0a6/README.md +0 -300
  40. synapse_pkg-2.0.0a6/pyproject.toml +0 -22
  41. synapse_pkg-2.0.0a6/synapse/__init__.py +0 -0
  42. synapse_pkg-2.0.0a6/synapse/cli.py +0 -28
  43. synapse_pkg-2.0.0a6/synapse/commands.py +0 -39
  44. synapse_pkg-2.0.0a6/synapse/extractor.py +0 -753
  45. synapse_pkg-2.0.0a6/synapse/git_manager.py +0 -490
  46. synapse_pkg-2.0.0a6/synapse/persistence.py +0 -131
  47. synapse_pkg-2.0.0a6/synapse/processor.py +0 -26
  48. synapse_pkg-2.0.0a6/synapse/provider.py +0 -8
  49. synapse_pkg-2.0.0a6/synapse_pkg.egg-info/PKG-INFO +0 -312
  50. synapse_pkg-2.0.0a6/synapse_pkg.egg-info/SOURCES.txt +0 -17
  51. synapse_pkg-2.0.0a6/synapse_pkg.egg-info/requires.txt +0 -2
  52. {synapse_pkg-2.0.0a6 → synapse_pkg-3.0.0}/setup.cfg +0 -0
  53. {synapse_pkg-2.0.0a6 → synapse_pkg-3.0.0}/synapse_pkg.egg-info/dependency_links.txt +0 -0
  54. {synapse_pkg-2.0.0a6 → synapse_pkg-3.0.0}/synapse_pkg.egg-info/entry_points.txt +0 -0
  55. {synapse_pkg-2.0.0a6 → synapse_pkg-3.0.0}/synapse_pkg.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
- # MIT License
1
+ MIT License
2
2
 
3
- Copyright (c) 2026 Piyush Garg
3
+ Copyright (c) 2026 Synapse Contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -0,0 +1,310 @@
1
+ Metadata-Version: 2.4
2
+ Name: synapse-pkg
3
+ Version: 3.0.0
4
+ Summary: Synapse: Repository Intelligence Engine — local-first structural analysis and retrieval for code repositories
5
+ Author: Piyush Garg
6
+ License: MIT
7
+ Requires-Python: >=3.10
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: tree-sitter<0.27,>=0.23
11
+ Requires-Dist: tree-sitter-python<0.26,>=0.23
12
+ Requires-Dist: tree-sitter-javascript<0.26,>=0.23
13
+ Requires-Dist: tree-sitter-typescript<0.24,>=0.23
14
+ Dynamic: license-file
15
+
16
+ # Synapse: Repository Intelligence Engine
17
+
18
+ Synapse is a local-first Repository Intelligence Engine that constructs and maintains a persistent, structured representation of a software codebase. It analyzes source files using Tree-sitter, builds a queryable knowledge graph, tracks code changes incrementally across Git commits, and provides deterministic structural retrieval and context synthesis for developers and external AI tools.
19
+
20
+ ---
21
+
22
+ ## 1. Installation
23
+
24
+ ### Requirements
25
+ - **Python**: `>= 3.10` (tested on Python 3.10, 3.11, 3.12, 3.13 on Windows and Linux)
26
+ - **Git**: `git` executable available in `PATH`
27
+
28
+ ### Standard Installation
29
+ Clone this repository and install into your active Python environment:
30
+
31
+ ```bash
32
+ git clone https://github.com/your-org/synapse.git
33
+ cd synapse
34
+ pip install .
35
+ ```
36
+
37
+ To install in development/testing mode with dependencies:
38
+ ```bash
39
+ pip install -e .
40
+ pip install pytest
41
+ ```
42
+
43
+ ---
44
+
45
+ ## 2. Quickstart
46
+
47
+ Run Synapse in any Git repository:
48
+
49
+ ```bash
50
+ # 1. Initialize Synapse tracking in the current repository
51
+ synapse init
52
+
53
+ # 2. Build the initial structural index
54
+ synapse index
55
+
56
+ # 3. View index health and repository status
57
+ synapse status
58
+
59
+ # 4. Search for symbols or files
60
+ synapse search UserService
61
+
62
+ # 5. Inspect a symbol, its hierarchy, and callers
63
+ synapse inspect UserService
64
+
65
+ # 6. Generate focused context for LLMs or review
66
+ synapse context get_user
67
+
68
+ # 7. Export the complete index
69
+ synapse export json -o index.json
70
+ synapse export md -o index.md
71
+ synapse export zip -o snapshot.zip
72
+ ```
73
+
74
+ ---
75
+
76
+ ## 3. Command Reference & Real Outputs
77
+
78
+ ### `synapse init`
79
+ Initializes `.synapse/` in the repository root and sets up the SQLite storage schema. Safe and idempotent to re-run on an existing repository without overwriting indexed data.
80
+
81
+ ```bash
82
+ $ synapse init
83
+ Synapse initialized successfully (schema v1).
84
+ ```
85
+
86
+ ### `synapse index [--rebuild] [--json]`
87
+ Scans tracked source files and updates the database.
88
+ - **Initial run**: Scans all eligible supported files at `HEAD` and saves a checkpoint.
89
+ - **Subsequent runs**: Computes `git diff` against the last checkpoint and updates only added, modified, deleted, or renamed files.
90
+ - `--rebuild`: Forces a complete rebuild from scratch, wiping stale records.
91
+ - `--json`: Emits raw indexing statistics as JSON.
92
+
93
+ ```bash
94
+ $ synapse index
95
+ Indexed 6 files, 9 symbols.
96
+ Files processed: 6
97
+ Symbols found: 9
98
+ ```
99
+
100
+ When run after commits modifying source code:
101
+ ```bash
102
+ $ synapse index
103
+ Incremental update: 5 files changed.
104
+ Added: 1, Modified: 2, Deleted: 1, Renamed: 1
105
+ ```
106
+
107
+ When run with no changes:
108
+ ```bash
109
+ $ synapse index
110
+ Repository unchanged since checkpoint cc17d9d8. Nothing to index.
111
+ ```
112
+
113
+ ### `synapse status [--json]`
114
+ Displays index state, commit checkpoint, error counts, and working tree cleanliness.
115
+
116
+ ```bash
117
+ $ synapse status
118
+ Synapse Status:
119
+ HEAD commit: acab2080
120
+ Last indexed: acab2080
121
+ Up to date: yes
122
+ Files indexed: 6
123
+ Symbols: 11
124
+ Edges: 27
125
+ ```
126
+
127
+ If the working tree has uncommitted modifications:
128
+ ```bash
129
+ $ synapse status
130
+ Synapse Status:
131
+ HEAD commit: acab2080
132
+ Last indexed: acab2080
133
+ Up to date: no (working tree dirty)
134
+ Warning: Working tree has uncommitted changes not reflected in the index.
135
+ ```
136
+
137
+ ### `synapse search <query> [--limit N] [--json]`
138
+ Searches symbols (by name and qualified name) and files. Results are ranked by match precision (exact match > prefix match > substring match).
139
+
140
+ ```bash
141
+ $ synapse search UserService
142
+ Found 2 result(s) for 'UserService':
143
+ class UserService (backend/services/user_service.py:3)
144
+ method UserService.get_user (backend/services/user_service.py:4)
145
+ ```
146
+
147
+ ### `synapse inspect <symbol> [--depth N] [--json]`
148
+ Inspects a specific symbol's definition, enclosing scope, base classes, subclasses, resolved callers/callees, imports, and unresolved references. Traverses relationships up to `--depth` hops (default: 1).
149
+
150
+ ```bash
151
+ $ synapse inspect UserService
152
+ Symbol: UserService (class)
153
+ File: backend/services/user_service.py:3-5
154
+ ID: 57992df372a7a124
155
+ Inherits from:
156
+ - BaseService (backend/base.py:1)
157
+ ```
158
+
159
+ If multiple symbols match the query, Synapse reports ambiguity and presents candidate options with locations rather than guessing:
160
+ ```bash
161
+ $ synapse inspect execute
162
+ Ambiguous symbol query 'execute'. Multiple symbols match:
163
+ - execute (method) in backend/base.py:3
164
+ - execute (method) in backend/services/worker.py:12
165
+ Specify the fully qualified name or refine query.
166
+ ```
167
+
168
+ ### `synapse context <query> [--max-results N] [--max-bytes N] [--depth N] [-o OUTPUT] [--json]`
169
+ Generates a structured, bounded context document around a symbol or query. Includes actual source snippets with line numbers, relationship graph neighbors up to `--depth`, and explicit listings of unresolved dependencies. Detects if disk source files are stale relative to `HEAD`.
170
+
171
+ ```bash
172
+ $ synapse context get_user
173
+ # Synapse Repository Context: get_user
174
+
175
+ Note: This context document was generated deterministically from static analysis. Snippets reflect indexed files. Dynamic calls, runtime reflection, and unindexed files remain unresolved and must not be assumed to be fully understood.
176
+
177
+ Found 1 item(s):
178
+
179
+ ## Method: UserService.get_user
180
+ Path: `backend/services/user_service.py` (Lines 4-5)
181
+ Reason: exact match
182
+ ```
183
+ def get_user(self, user_id: int):
184
+ return self.execute()
185
+ ```
186
+ Calls:
187
+ - BaseService.execute (backend/base.py:4)
188
+ ```
189
+
190
+ ### `synapse export <json|md|zip> [-o OUTPUT]`
191
+ Exports canonical index data into portable formats.
192
+ - **json**: Full schema-versioned JSON dump containing files, symbols, references, and edges.
193
+ - **md**: Deterministic Markdown reference document detailing repository architecture.
194
+ - **zip**: Self-contained archive package containing `index.json`, `index.md`, and `README.txt` with deterministic timestamps.
195
+
196
+ ```bash
197
+ $ synapse export json -o synapse_export.json
198
+ Exported JSON index to synapse_export.json
199
+
200
+ $ synapse export md -o synapse_export.md
201
+ Exported Markdown overview to synapse_export.md
202
+
203
+ $ synapse export zip -o synapse_export.zip
204
+ Exported ZIP snapshot to synapse_export.zip
205
+ ```
206
+
207
+ ---
208
+
209
+ ## 4. Index Semantics & Architecture
210
+
211
+ ```
212
+ Git Repository (HEAD)
213
+ │
214
+ Git Diff (-M -z) ─── Incremental Change Detection
215
+ │
216
+ Tree-sitter ──────── Language Parsers (Python, JS, TS, TSX)
217
+ │
218
+ AST Analyzers ────── Structural Extraction (Symbols, Imports, Inheritance, Calls)
219
+ │
220
+ SQLite Index ─────── Persistent Storage (.synapse/index.db)
221
+ │
222
+ Graph Builder ────── Edge Generation & Cross-File Reference Resolution
223
+ │
224
+ Retrieval Engine ─── Search, Inspect, Context & Deterministic Exports
225
+ ```
226
+
227
+ - **Source of Truth**: The Git commit tree at `HEAD` is the authoritative source of truth.
228
+ - **Committed State vs Working Tree**: Synapse indexes committed repository states. `synapse status` informs the user if the local working tree has uncommitted edits.
229
+ - **Transactional Updates**: All index writes, deletes, and checkpoint updates occur within atomic SQLite transactions. If a parsing or indexing error occurs mid-run, changes roll back and the checkpoint is not advanced.
230
+ - **Zero Modification Guarantee**: Synapse NEVER writes to, modifies, or deletes user source files. All internal metadata resides strictly in `.synapse/index.db`.
231
+
232
+ ---
233
+
234
+ ## 5. Exclusions & Safety
235
+
236
+ Synapse automatically excludes paths matching standard ignored patterns:
237
+ - Version control metadata: `.git`, `.gitignore`
238
+ - Synapse metadata: `.synapse`, `synapse_export.*`
239
+ - Virtual environments: `.venv`, `venv`, `env`, `virtualenv`
240
+ - Package dependencies: `node_modules`, `site-packages`, `vendor`, `bower_components`
241
+ - Build outputs: `dist`, `build`, `out`, `target`, `bin`, `obj`
242
+ - Cache directories: `__pycache__`, `.pytest_cache`, `.mypy_cache`, `.cache`, `.parcel-cache`
243
+ - Binary and media files: `.exe`, `.dll`, `.so`, `.zip`, `.tar`, `.gz`, `.png`, `.jpg`, `.pdf`, etc.
244
+ - Large files exceeding the maximum file size cap (default: 10 MB)
245
+
246
+ ---
247
+
248
+ ## 6. Exit Codes
249
+
250
+ Synapse adheres to standard UNIX CLI exit codes:
251
+ - `0`: Success. Operation completed cleanly.
252
+ - `1`: Operational error (e.g., repository not initialized, non-Git directory, corrupt DB, file read error).
253
+ - `2`: CLI usage / argument syntax error (e.g., missing required argument, invalid command).
254
+
255
+ ---
256
+
257
+ ## 7. Supported Languages & Extracted Entities
258
+
259
+ | Language | Extensions | Extracted Symbols | Relationships Captured |
260
+ |---|---|---|---|
261
+ | **Python** | `.py` | Classes, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM`, `CALLS`, `IMPORTS`, `REFERENCES` |
262
+ | **JavaScript** | `.js`, `.jsx`, `.mjs`, `.cjs` | Classes, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM` (class extends), `CALLS`, `IMPORTS`, `REFERENCES` |
263
+ | **TypeScript / TSX** | `.ts`, `.tsx` | Classes, Interfaces, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM` (extends / implements), `CALLS`, `IMPORTS`, `REFERENCES` |
264
+
265
+ ---
266
+
267
+ ## 8. Explicit Limitations
268
+
269
+ Synapse is designed to provide **provable, statically defensible** structural representations without inventing runtime behavior:
270
+ - **Dynamic Invocations**: Dynamic dispatch, runtime `getattr()` / `eval()`, dynamic imports (`import()`, `require(variable)`), and metaprogramming constructs remain marked as `unresolved`.
271
+ - **Runtime Reflection**: Reflection-based dependency injection and indirect plugin registries cannot be inferred statically.
272
+ - **Decorators**: Decorators that mutate function signatures or wrap callable targets are indexed syntactically; runtime wrapper execution paths are not fabricated.
273
+ - **Cross-Package Externals**: External package dependencies (e.g., standard library, third-party libraries outside the repository) are identified as module imports, but their external internal symbol graphs are not parsed.
274
+ - **Re-exports**: Multi-level star re-exports (`export * from '...'`) across nested modules are tracked up to direct resolvable symbol bindings.
275
+
276
+ ---
277
+
278
+ ## 9. Recovery & Maintenance
279
+
280
+ If the index database is ever corrupted or state needs to be resynchronized:
281
+ ```bash
282
+ # Force a full rebuild of the repository index from HEAD
283
+ synapse index --rebuild
284
+ ```
285
+
286
+ If `.synapse/index.db` is physically damaged or truncated:
287
+ ```bash
288
+ # Remove corrupted database file and re-initialize
289
+ rm .synapse/index.db
290
+ synapse init
291
+ synapse index
292
+ ```
293
+
294
+ ---
295
+
296
+ ## 10. Development & Testing
297
+
298
+ Synapse includes an exhaustive test suite covering all 9 engineering phases:
299
+ ```bash
300
+ # Run the full test suite
301
+ pytest tests/ -v
302
+ ```
303
+
304
+ All 70 tests run locally with zero network calls, zero LLM dependencies, and automatic cleanup of temporary Git repositories.
305
+
306
+ ---
307
+
308
+ ## 11. License
309
+
310
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,295 @@
1
+ # Synapse: Repository Intelligence Engine
2
+
3
+ Synapse is a local-first Repository Intelligence Engine that constructs and maintains a persistent, structured representation of a software codebase. It analyzes source files using Tree-sitter, builds a queryable knowledge graph, tracks code changes incrementally across Git commits, and provides deterministic structural retrieval and context synthesis for developers and external AI tools.
4
+
5
+ ---
6
+
7
+ ## 1. Installation
8
+
9
+ ### Requirements
10
+ - **Python**: `>= 3.10` (tested on Python 3.10, 3.11, 3.12, 3.13 on Windows and Linux)
11
+ - **Git**: `git` executable available in `PATH`
12
+
13
+ ### Standard Installation
14
+ Clone this repository and install into your active Python environment:
15
+
16
+ ```bash
17
+ git clone https://github.com/your-org/synapse.git
18
+ cd synapse
19
+ pip install .
20
+ ```
21
+
22
+ To install in development/testing mode with dependencies:
23
+ ```bash
24
+ pip install -e .
25
+ pip install pytest
26
+ ```
27
+
28
+ ---
29
+
30
+ ## 2. Quickstart
31
+
32
+ Run Synapse in any Git repository:
33
+
34
+ ```bash
35
+ # 1. Initialize Synapse tracking in the current repository
36
+ synapse init
37
+
38
+ # 2. Build the initial structural index
39
+ synapse index
40
+
41
+ # 3. View index health and repository status
42
+ synapse status
43
+
44
+ # 4. Search for symbols or files
45
+ synapse search UserService
46
+
47
+ # 5. Inspect a symbol, its hierarchy, and callers
48
+ synapse inspect UserService
49
+
50
+ # 6. Generate focused context for LLMs or review
51
+ synapse context get_user
52
+
53
+ # 7. Export the complete index
54
+ synapse export json -o index.json
55
+ synapse export md -o index.md
56
+ synapse export zip -o snapshot.zip
57
+ ```
58
+
59
+ ---
60
+
61
+ ## 3. Command Reference & Real Outputs
62
+
63
+ ### `synapse init`
64
+ Initializes `.synapse/` in the repository root and sets up the SQLite storage schema. Safe and idempotent to re-run on an existing repository without overwriting indexed data.
65
+
66
+ ```bash
67
+ $ synapse init
68
+ Synapse initialized successfully (schema v1).
69
+ ```
70
+
71
+ ### `synapse index [--rebuild] [--json]`
72
+ Scans tracked source files and updates the database.
73
+ - **Initial run**: Scans all eligible supported files at `HEAD` and saves a checkpoint.
74
+ - **Subsequent runs**: Computes `git diff` against the last checkpoint and updates only added, modified, deleted, or renamed files.
75
+ - `--rebuild`: Forces a complete rebuild from scratch, wiping stale records.
76
+ - `--json`: Emits raw indexing statistics as JSON.
77
+
78
+ ```bash
79
+ $ synapse index
80
+ Indexed 6 files, 9 symbols.
81
+ Files processed: 6
82
+ Symbols found: 9
83
+ ```
84
+
85
+ When run after commits modifying source code:
86
+ ```bash
87
+ $ synapse index
88
+ Incremental update: 5 files changed.
89
+ Added: 1, Modified: 2, Deleted: 1, Renamed: 1
90
+ ```
91
+
92
+ When run with no changes:
93
+ ```bash
94
+ $ synapse index
95
+ Repository unchanged since checkpoint cc17d9d8. Nothing to index.
96
+ ```
97
+
98
+ ### `synapse status [--json]`
99
+ Displays index state, commit checkpoint, error counts, and working tree cleanliness.
100
+
101
+ ```bash
102
+ $ synapse status
103
+ Synapse Status:
104
+ HEAD commit: acab2080
105
+ Last indexed: acab2080
106
+ Up to date: yes
107
+ Files indexed: 6
108
+ Symbols: 11
109
+ Edges: 27
110
+ ```
111
+
112
+ If the working tree has uncommitted modifications:
113
+ ```bash
114
+ $ synapse status
115
+ Synapse Status:
116
+ HEAD commit: acab2080
117
+ Last indexed: acab2080
118
+ Up to date: no (working tree dirty)
119
+ Warning: Working tree has uncommitted changes not reflected in the index.
120
+ ```
121
+
122
+ ### `synapse search <query> [--limit N] [--json]`
123
+ Searches symbols (by name and qualified name) and files. Results are ranked by match precision (exact match > prefix match > substring match).
124
+
125
+ ```bash
126
+ $ synapse search UserService
127
+ Found 2 result(s) for 'UserService':
128
+ class UserService (backend/services/user_service.py:3)
129
+ method UserService.get_user (backend/services/user_service.py:4)
130
+ ```
131
+
132
+ ### `synapse inspect <symbol> [--depth N] [--json]`
133
+ Inspects a specific symbol's definition, enclosing scope, base classes, subclasses, resolved callers/callees, imports, and unresolved references. Traverses relationships up to `--depth` hops (default: 1).
134
+
135
+ ```bash
136
+ $ synapse inspect UserService
137
+ Symbol: UserService (class)
138
+ File: backend/services/user_service.py:3-5
139
+ ID: 57992df372a7a124
140
+ Inherits from:
141
+ - BaseService (backend/base.py:1)
142
+ ```
143
+
144
+ If multiple symbols match the query, Synapse reports ambiguity and presents candidate options with locations rather than guessing:
145
+ ```bash
146
+ $ synapse inspect execute
147
+ Ambiguous symbol query 'execute'. Multiple symbols match:
148
+ - execute (method) in backend/base.py:3
149
+ - execute (method) in backend/services/worker.py:12
150
+ Specify the fully qualified name or refine query.
151
+ ```
152
+
153
+ ### `synapse context <query> [--max-results N] [--max-bytes N] [--depth N] [-o OUTPUT] [--json]`
154
+ Generates a structured, bounded context document around a symbol or query. Includes actual source snippets with line numbers, relationship graph neighbors up to `--depth`, and explicit listings of unresolved dependencies. Detects if disk source files are stale relative to `HEAD`.
155
+
156
+ ```bash
157
+ $ synapse context get_user
158
+ # Synapse Repository Context: get_user
159
+
160
+ Note: This context document was generated deterministically from static analysis. Snippets reflect indexed files. Dynamic calls, runtime reflection, and unindexed files remain unresolved and must not be assumed to be fully understood.
161
+
162
+ Found 1 item(s):
163
+
164
+ ## Method: UserService.get_user
165
+ Path: `backend/services/user_service.py` (Lines 4-5)
166
+ Reason: exact match
167
+ ```
168
+ def get_user(self, user_id: int):
169
+ return self.execute()
170
+ ```
171
+ Calls:
172
+ - BaseService.execute (backend/base.py:4)
173
+ ```
174
+
175
+ ### `synapse export <json|md|zip> [-o OUTPUT]`
176
+ Exports canonical index data into portable formats.
177
+ - **json**: Full schema-versioned JSON dump containing files, symbols, references, and edges.
178
+ - **md**: Deterministic Markdown reference document detailing repository architecture.
179
+ - **zip**: Self-contained archive package containing `index.json`, `index.md`, and `README.txt` with deterministic timestamps.
180
+
181
+ ```bash
182
+ $ synapse export json -o synapse_export.json
183
+ Exported JSON index to synapse_export.json
184
+
185
+ $ synapse export md -o synapse_export.md
186
+ Exported Markdown overview to synapse_export.md
187
+
188
+ $ synapse export zip -o synapse_export.zip
189
+ Exported ZIP snapshot to synapse_export.zip
190
+ ```
191
+
192
+ ---
193
+
194
+ ## 4. Index Semantics & Architecture
195
+
196
+ ```
197
+ Git Repository (HEAD)
198
+ │
199
+ Git Diff (-M -z) ─── Incremental Change Detection
200
+ │
201
+ Tree-sitter ──────── Language Parsers (Python, JS, TS, TSX)
202
+ │
203
+ AST Analyzers ────── Structural Extraction (Symbols, Imports, Inheritance, Calls)
204
+ │
205
+ SQLite Index ─────── Persistent Storage (.synapse/index.db)
206
+ │
207
+ Graph Builder ────── Edge Generation & Cross-File Reference Resolution
208
+ │
209
+ Retrieval Engine ─── Search, Inspect, Context & Deterministic Exports
210
+ ```
211
+
212
+ - **Source of Truth**: The Git commit tree at `HEAD` is the authoritative source of truth.
213
+ - **Committed State vs Working Tree**: Synapse indexes committed repository states. `synapse status` informs the user if the local working tree has uncommitted edits.
214
+ - **Transactional Updates**: All index writes, deletes, and checkpoint updates occur within atomic SQLite transactions. If a parsing or indexing error occurs mid-run, changes roll back and the checkpoint is not advanced.
215
+ - **Zero Modification Guarantee**: Synapse NEVER writes to, modifies, or deletes user source files. All internal metadata resides strictly in `.synapse/index.db`.
216
+
217
+ ---
218
+
219
+ ## 5. Exclusions & Safety
220
+
221
+ Synapse automatically excludes paths matching standard ignored patterns:
222
+ - Version control metadata: `.git`, `.gitignore`
223
+ - Synapse metadata: `.synapse`, `synapse_export.*`
224
+ - Virtual environments: `.venv`, `venv`, `env`, `virtualenv`
225
+ - Package dependencies: `node_modules`, `site-packages`, `vendor`, `bower_components`
226
+ - Build outputs: `dist`, `build`, `out`, `target`, `bin`, `obj`
227
+ - Cache directories: `__pycache__`, `.pytest_cache`, `.mypy_cache`, `.cache`, `.parcel-cache`
228
+ - Binary and media files: `.exe`, `.dll`, `.so`, `.zip`, `.tar`, `.gz`, `.png`, `.jpg`, `.pdf`, etc.
229
+ - Large files exceeding the maximum file size cap (default: 10 MB)
230
+
231
+ ---
232
+
233
+ ## 6. Exit Codes
234
+
235
+ Synapse adheres to standard UNIX CLI exit codes:
236
+ - `0`: Success. Operation completed cleanly.
237
+ - `1`: Operational error (e.g., repository not initialized, non-Git directory, corrupt DB, file read error).
238
+ - `2`: CLI usage / argument syntax error (e.g., missing required argument, invalid command).
239
+
240
+ ---
241
+
242
+ ## 7. Supported Languages & Extracted Entities
243
+
244
+ | Language | Extensions | Extracted Symbols | Relationships Captured |
245
+ |---|---|---|---|
246
+ | **Python** | `.py` | Classes, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM`, `CALLS`, `IMPORTS`, `REFERENCES` |
247
+ | **JavaScript** | `.js`, `.jsx`, `.mjs`, `.cjs` | Classes, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM` (class extends), `CALLS`, `IMPORTS`, `REFERENCES` |
248
+ | **TypeScript / TSX** | `.ts`, `.tsx` | Classes, Interfaces, Methods, Functions | `CONTAINS`, `DEFINES`, `INHERITS_FROM` (extends / implements), `CALLS`, `IMPORTS`, `REFERENCES` |
249
+
250
+ ---
251
+
252
+ ## 8. Explicit Limitations
253
+
254
+ Synapse is designed to provide **provable, statically defensible** structural representations without inventing runtime behavior:
255
+ - **Dynamic Invocations**: Dynamic dispatch, runtime `getattr()` / `eval()`, dynamic imports (`import()`, `require(variable)`), and metaprogramming constructs remain marked as `unresolved`.
256
+ - **Runtime Reflection**: Reflection-based dependency injection and indirect plugin registries cannot be inferred statically.
257
+ - **Decorators**: Decorators that mutate function signatures or wrap callable targets are indexed syntactically; runtime wrapper execution paths are not fabricated.
258
+ - **Cross-Package Externals**: External package dependencies (e.g., standard library, third-party libraries outside the repository) are identified as module imports, but their external internal symbol graphs are not parsed.
259
+ - **Re-exports**: Multi-level star re-exports (`export * from '...'`) across nested modules are tracked up to direct resolvable symbol bindings.
260
+
261
+ ---
262
+
263
+ ## 9. Recovery & Maintenance
264
+
265
+ If the index database is ever corrupted or state needs to be resynchronized:
266
+ ```bash
267
+ # Force a full rebuild of the repository index from HEAD
268
+ synapse index --rebuild
269
+ ```
270
+
271
+ If `.synapse/index.db` is physically damaged or truncated:
272
+ ```bash
273
+ # Remove corrupted database file and re-initialize
274
+ rm .synapse/index.db
275
+ synapse init
276
+ synapse index
277
+ ```
278
+
279
+ ---
280
+
281
+ ## 10. Development & Testing
282
+
283
+ Synapse includes an exhaustive test suite covering all 9 engineering phases:
284
+ ```bash
285
+ # Run the full test suite
286
+ pytest tests/ -v
287
+ ```
288
+
289
+ All 70 tests run locally with zero network calls, zero LLM dependencies, and automatic cleanup of temporary Git repositories.
290
+
291
+ ---
292
+
293
+ ## 11. License
294
+
295
+ MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,31 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "synapse-pkg"
7
+ version = "3.0.0"
8
+ description = "Synapse: Repository Intelligence Engine — local-first structural analysis and retrieval for code repositories"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.10"
12
+ authors = [
13
+ {name = "Piyush Garg"}
14
+ ]
15
+
16
+ dependencies = [
17
+ "tree-sitter>=0.23,<0.27",
18
+ "tree-sitter-python>=0.23,<0.26",
19
+ "tree-sitter-javascript>=0.23,<0.26",
20
+ "tree-sitter-typescript>=0.23,<0.24",
21
+ ]
22
+
23
+ [project.scripts]
24
+ synapse = "synapse.cli:main"
25
+
26
+ [tool.setuptools.packages.find]
27
+ include = ["synapse*"]
28
+
29
+ [tool.pytest.ini_options]
30
+ testpaths = ["tests"]
31
+ addopts = "-v --tb=short"
@@ -0,0 +1,3 @@
1
+ """Synapse: Repository Intelligence Engine."""
2
+
3
+ __version__ = "0.1.0"
@@ -0,0 +1 @@
1
+ """Language-specific structural analysis."""