Metadata-Version: 2.5
Name: synapse-ast
Version: 0.1.0
Summary: AST-driven dependency tracer and token calculator for AI-assisted coding workflows.
Author: Aswin
License-Expression: MIT
License-File: LICENSE
Keywords: ast,cli,context-window,dependency-graph,llm,tiktoken
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Code Generators
Requires-Python: >=3.10
Requires-Dist: tiktoken>=0.5
Requires-Dist: typer>=0.12
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == 'dev'
Description-Content-Type: text/markdown

# synapse

AST-driven dependency tracer and token calculator for AI-assisted coding workflows.

Instead of dumping entire folders into an LLM's context window, `synapse` walks
your Python codebase's import graph (including `src/` layouts, relative imports,
`__init__.py` re-exports, and namespace packages) and extracts only the files —
or referenced symbols — transitively relevant to your target file, with token
counts so you know exactly what you're spending.

## Install

```bash
pip install synapse-ast
```

For local development with tests:

```bash
pip install -e ".[dev]"
pytest
```

## Usage

```bash
synapse --version
synapse map .                                  # scan a repo, print structural summary
synapse map . --json                           # machine-readable JSON summary
synapse pack path/to/file.py                   # pack dependency chain to stdout
synapse pack file.py --depth 3 --budget 8000   # limit depth and warn if over token budget
synapse pack file.py --symbols                 # slice dependencies to referenced defs/classes
synapse pack file.py --format markdown         # text | markdown | xml | json
synapse pack file.py --exclude-type-checking   # skip `if TYPE_CHECKING:` imports
synapse pack file.py --output clipboard        # copy to clipboard (or --output file --out-file out.txt)
```

### Key options

- `--root <path>`: repository root (defaults to `.`).
- `--depth, -d <int>`: maximum traversal depth for local dependencies (default `2`).
- `--budget, -b <int>`: token budget; prints a warning to `stderr` if stripped tokens exceed budget.
- `--symbols / --full-files`: slice dependency files (`depth >= 1`) to only referenced functions, classes, constants, and imports while keeping the target intact (default: `--full-files`).
- `--format, -f <fmt>`: output format (`text`, `markdown`, `xml`, `json`; default `text`).
- `--output, -o <dest>`: destination (`stdout`, `clipboard`, `file`; default `stdout`) with `--out-file`.
- `--strip-comments / --keep-comments`, `--strip-docstrings / --keep-docstrings`, `--strip-blank / --keep-blank`.
- `--include-type-checking / --exclude-type-checking`: include or exclude `if TYPE_CHECKING:` blocks (default: include).
- `--no-cache`: ignore and bypass `.synapse/cache.json` for a full re-parse.

## Design notes

- **Clean `stdout`/`stderr` split on `pack`:** only packed code goes to `stdout` so `synapse pack file.py > context.txt` stays clean; cache stats, token tables, and warnings go to `stderr`.
- **Offline `tiktoken` fallback:** `cl100k_base` is used when available; if `tiktoken` cannot download its BPE table (e.g. offline/corporate proxy), `synapse` degrades gracefully to an approximate `~4 chars/token` estimate and labels the output as approximate on `stderr`.
- **Caching (`.synapse/`):** parsed AST symbol maps are cached in `.synapse/cache.json` using mtime + SHA-256 invalidation, and `.synapse/` is automatically added to `.gitignore` on first cached run.
