context-map is a Rust CLI that scans a repository and generates a Markdown context file for coding agents.
It extracts:
- exported functions
- exported type aliases
- exported interfaces
from:
.ts.tsx.vue(<script>blocks)
and writes a structured REPO.md with:
- repository tree
- exported functions grouped by file
- optional type inventory grouped by file
- parse error report
Agents often duplicate code when they do not quickly see repo shape and existing symbols.
context-map gives a compact index that helps agents:
- navigate modules faster
- discover existing utilities/types
- reduce redundant implementations
- Syntax-aware parsing via Tree-sitter (no regex scraping)
- TS, TSX, Vue
<script>support - Grouped output by file path
- Token-efficient profiles (
compact,balanced,detailed) - Optional type inventory (
--no-types) - Configurable repository tree depth (
--tree-depth) - Parse errors are non-fatal and reported per file
Prerequisites:
- Rust toolchain (stable)
Build:
cargo build --releaseBinary path:
./target/release/context-mapRun without building release:
cargo run -- --root .context-map --root <path> [--out <file>] [--profile <compact|balanced|detailed>] [--no-types] [--tree-depth <N>]-
--root <path>- Root directory to scan
- Default:
.
-
--out <file>- Output Markdown file path
- Default:
<root>/REPO.md
-
--profile <compact|balanced|detailed>- Controls symbol formatting verbosity
- Default:
balanced
-
--no-types- Disables the
Type Inventorysection
- Disables the
-
--tree-depth <N>- Max depth for repository structure tree
- Default:
10
- Functions: name only
- Types: name only
- No line markers
- Best for lowest token usage
- Functions:
name(params) - Types: name only
- No line markers
- Best quality/token balance
- Functions: full normalized signature +
@L<line> - Types: name +
@L<line> - Best when precise location detail is needed
Source files considered for extraction:
*.ts*.tsx*.vue
Ignored source files:
*.d.ts*.props.ts(exact suffix rule)
Notes:
.props.tsxis not ignored- Vue
script src="..."blocks are skipped
These directories are excluded from traversal:
.gitnode_modulesdistbuildtarget- hidden nested directories (names starting with
.below root)
Included:
export function foo(...) {}export const foo = (...) => ...export const foo = function (...) {}
Included:
export interface Foo { ... }export type Foo = ...
- Re-export lists/forwarding forms such as:
export { foo }export { foo } from "./x"export * from "./x"
Generated Markdown sections:
# Repository Structure# Exported Functions# Type Inventory(unless--no-types)## Parse Errors(only when present)
Entries are grouped by file:
### `src/utils/math.ts`
- `sum(a: number, b: number)`
- `average(values: number[])`Default (balanced):
cargo run -- --root /path/to/repoToken-lean for agent prompts:
cargo run -- --root /path/to/repo --profile compact --no-types --tree-depth 4Detailed audit mode:
cargo run -- --root /path/to/repo --profile detailed --tree-depth 12Custom output file:
cargo run -- --root /path/to/repo --out /tmp/context-map.md- Exit
0on successful run (including when no exports are found) - Non-zero on fatal errors (invalid root, parser init failure, output write failure)
Per-file parse/read failures are reported under ## Parse Errors and do not fail the whole run.
Run tests:
cargo testProject layout:
src/main.rs: CLI argument parsing and command entrypointsrc/lib.rs: orchestration, config, run pipelinesrc/walker.rs: file/repo traversal and ignore filteringsrc/parser.rs: Tree-sitter extraction for functions/typessrc/markdown.rs: Markdown rendering by profiletests/context_map_integration.rs: end-to-end integration checks
The crate exposes APIs used by the CLI:
generate_context_map(root: &Path)generate_context_map_with_depth(root: &Path, tree_depth: usize)run(root: &Path, out: &Path)run_with_config(root: &Path, out: &Path, config: RenderConfig)
Core config:
RenderProfile::{Compact, Balanced, Detailed}RenderConfig { profile, include_types, tree_depth }
- Re-export resolution is intentionally out of scope
- Only TypeScript-family exports are indexed (TS/TSX/Vue script)
- Function extraction is declaration-based (not class/object method inventory)
No license file is currently present in this repository.