tokenlean 0.1.0
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.
- package/README.md +248 -0
- package/bin/tl-api.mjs +515 -0
- package/bin/tl-blame.mjs +345 -0
- package/bin/tl-complexity.mjs +514 -0
- package/bin/tl-component.mjs +274 -0
- package/bin/tl-config.mjs +135 -0
- package/bin/tl-context.mjs +156 -0
- package/bin/tl-coverage.mjs +456 -0
- package/bin/tl-deps.mjs +474 -0
- package/bin/tl-diff.mjs +183 -0
- package/bin/tl-entry.mjs +256 -0
- package/bin/tl-env.mjs +376 -0
- package/bin/tl-exports.mjs +583 -0
- package/bin/tl-flow.mjs +324 -0
- package/bin/tl-history.mjs +289 -0
- package/bin/tl-hotspots.mjs +321 -0
- package/bin/tl-impact.mjs +345 -0
- package/bin/tl-prompt.mjs +175 -0
- package/bin/tl-related.mjs +227 -0
- package/bin/tl-routes.mjs +627 -0
- package/bin/tl-search.mjs +123 -0
- package/bin/tl-structure.mjs +161 -0
- package/bin/tl-symbols.mjs +430 -0
- package/bin/tl-todo.mjs +341 -0
- package/bin/tl-types.mjs +441 -0
- package/bin/tl-unused.mjs +494 -0
- package/package.json +55 -0
- package/src/config.mjs +271 -0
- package/src/output.mjs +251 -0
- package/src/project.mjs +277 -0
package/README.md
ADDED
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# tokenlean
|
|
2
|
+
|
|
3
|
+
Lean CLI tools for AI agents and developers. Reduce context usage, save tokens, improve workflow efficiency.
|
|
4
|
+
|
|
5
|
+
## The Problem
|
|
6
|
+
|
|
7
|
+
AI coding assistants are powerful, but they have a fundamental constraint: **context windows**. Every file you read,
|
|
8
|
+
every search result, every piece of context consumes tokens. This matters because:
|
|
9
|
+
|
|
10
|
+
- **Cost**: More tokens = higher API costs
|
|
11
|
+
- **Quality**: Overstuffed context leads to worse responses
|
|
12
|
+
- **Speed**: Larger contexts take longer to process
|
|
13
|
+
- **Limits**: Hit the ceiling and the AI loses important information
|
|
14
|
+
|
|
15
|
+
Most developers (and AI agents) approach codebases inefficiently - reading entire files when they only need function
|
|
16
|
+
signatures, grepping repeatedly when a structured search would do, or diving into implementation before understanding
|
|
17
|
+
the API surface.
|
|
18
|
+
|
|
19
|
+
## The Solution
|
|
20
|
+
|
|
21
|
+
tokenlean provides **25 specialized CLI tools** that give you (or your AI agent) exactly the information needed - no
|
|
22
|
+
more, no less. Each tool is designed to answer a specific question about your codebase with minimal token overhead.
|
|
23
|
+
|
|
24
|
+
Instead of reading a 500-line file to understand its exports, run `tl-exports` (~50 tokens). Instead of reading all your
|
|
25
|
+
types to understand data shapes, run `tl-types` (~100 tokens). Instead of guessing which files might be affected by a
|
|
26
|
+
change, run `tl-impact` and know for sure.
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
npm install -g tokenlean
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Or link locally for development:
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
git clone https://github.com/edimuj/tokenlean.git
|
|
38
|
+
cd tokenlean
|
|
39
|
+
npm link
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
## Quick Start
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
# Get project overview
|
|
46
|
+
tl-structure
|
|
47
|
+
|
|
48
|
+
# Before reading a file - check its size
|
|
49
|
+
tl-context src/api/
|
|
50
|
+
|
|
51
|
+
# Get function signatures without bodies
|
|
52
|
+
tl-symbols src/utils.ts
|
|
53
|
+
|
|
54
|
+
# Understand what a module exports
|
|
55
|
+
tl-exports src/lib/
|
|
56
|
+
|
|
57
|
+
# Check what would break if you change a file
|
|
58
|
+
tl-impact src/core/auth.ts
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## AI Agent Integration
|
|
62
|
+
|
|
63
|
+
Add tokenlean instructions to your AI tool's config:
|
|
64
|
+
|
|
65
|
+
| AI Tool | Config File | Command |
|
|
66
|
+
|----------------|-----------------------------------|------------------------------------------------|
|
|
67
|
+
| Claude Code | `CLAUDE.md` | `tl-prompt >> CLAUDE.md` |
|
|
68
|
+
| Cursor | `.cursorrules` | `tl-prompt --minimal >> .cursorrules` |
|
|
69
|
+
| GitHub Copilot | `.github/copilot-instructions.md` | `tl-prompt >> .github/copilot-instructions.md` |
|
|
70
|
+
| Windsurf | `.windsurfrules` | `tl-prompt --minimal >> .windsurfrules` |
|
|
71
|
+
|
|
72
|
+
The `--minimal` flag produces a compact version that uses fewer tokens.
|
|
73
|
+
|
|
74
|
+
## Tools Reference
|
|
75
|
+
|
|
76
|
+
### Before Reading Files
|
|
77
|
+
|
|
78
|
+
These tools help you understand code structure without reading full implementations.
|
|
79
|
+
|
|
80
|
+
| Tool | Description | Example |
|
|
81
|
+
|----------------|------------------------------------------|---------------------------|
|
|
82
|
+
| `tl-structure` | Project overview with token estimates | `tl-structure src/` |
|
|
83
|
+
| `tl-context` | Estimate token usage for files/dirs | `tl-context src/api/` |
|
|
84
|
+
| `tl-symbols` | Function/class signatures without bodies | `tl-symbols src/utils.ts` |
|
|
85
|
+
| `tl-types` | Full TypeScript type definitions | `tl-types src/types/` |
|
|
86
|
+
| `tl-exports` | Public API surface of a module | `tl-exports src/lib/` |
|
|
87
|
+
| `tl-component` | React component analyzer (props, hooks) | `tl-component Button.tsx` |
|
|
88
|
+
| `tl-entry` | Find entry points and main files | `tl-entry src/` |
|
|
89
|
+
|
|
90
|
+
### Before Modifying Files
|
|
91
|
+
|
|
92
|
+
Understand dependencies and impact before making changes.
|
|
93
|
+
|
|
94
|
+
| Tool | Description | Example |
|
|
95
|
+
|-----------------|---------------------------------------------|-------------------------------------|
|
|
96
|
+
| `tl-impact` | Blast radius - what depends on this file | `tl-impact src/auth.ts` |
|
|
97
|
+
| `tl-deps` | Show what a file imports (with tree mode) | `tl-deps src/api.ts --tree` |
|
|
98
|
+
| `tl-related` | Find tests, types, and importers | `tl-related src/Button.tsx` |
|
|
99
|
+
| `tl-flow` | Call graph - what calls this, what it calls | `tl-flow src/utils.ts` |
|
|
100
|
+
| `tl-coverage` | Test coverage info for files | `tl-coverage src/` |
|
|
101
|
+
| `tl-complexity` | Code complexity metrics | `tl-complexity src/ --threshold 10` |
|
|
102
|
+
|
|
103
|
+
### Understanding History
|
|
104
|
+
|
|
105
|
+
Track changes and authorship efficiently.
|
|
106
|
+
|
|
107
|
+
| Tool | Description | Example |
|
|
108
|
+
|---------------|----------------------------------|-------------------------|
|
|
109
|
+
| `tl-diff` | Token-efficient git diff summary | `tl-diff --staged` |
|
|
110
|
+
| `tl-history` | Recent commits for a file | `tl-history src/api.ts` |
|
|
111
|
+
| `tl-blame` | Compact per-line authorship | `tl-blame src/api.ts` |
|
|
112
|
+
| `tl-hotspots` | Frequently changed files (churn) | `tl-hotspots --days 30` |
|
|
113
|
+
|
|
114
|
+
### Finding Things
|
|
115
|
+
|
|
116
|
+
Search and discover code patterns.
|
|
117
|
+
|
|
118
|
+
| Tool | Description | Example |
|
|
119
|
+
|-------------|------------------------------------|--------------------------|
|
|
120
|
+
| `tl-search` | Run pre-defined search patterns | `tl-search hooks` |
|
|
121
|
+
| `tl-todo` | Find TODOs/FIXMEs in codebase | `tl-todo src/` |
|
|
122
|
+
| `tl-env` | Find environment variables used | `tl-env --required-only` |
|
|
123
|
+
| `tl-unused` | Find unused exports/files | `tl-unused src/` |
|
|
124
|
+
| `tl-api` | Extract REST/GraphQL endpoints | `tl-api src/routes/` |
|
|
125
|
+
| `tl-routes` | Extract routes from web frameworks | `tl-routes app/` |
|
|
126
|
+
|
|
127
|
+
### Configuration & Utilities
|
|
128
|
+
|
|
129
|
+
| Tool | Description | Example |
|
|
130
|
+
|-------------|--------------------------------|-----------------------|
|
|
131
|
+
| `tl-config` | Show/manage configuration | `tl-config --init` |
|
|
132
|
+
| `tl-prompt` | Generate AI agent instructions | `tl-prompt --minimal` |
|
|
133
|
+
|
|
134
|
+
## Common Options
|
|
135
|
+
|
|
136
|
+
All tools support these flags:
|
|
137
|
+
|
|
138
|
+
```
|
|
139
|
+
-l N, --max-lines N Limit output to N lines
|
|
140
|
+
-t N, --max-tokens N Limit output to ~N tokens
|
|
141
|
+
-j, --json Output as JSON (for piping)
|
|
142
|
+
-q, --quiet Minimal output (no headers/stats)
|
|
143
|
+
-h, --help Show help
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
## Configuration
|
|
147
|
+
|
|
148
|
+
tokenlean uses `.tokenleanrc.json` for configuration:
|
|
149
|
+
|
|
150
|
+
- **Project config**: `.tokenleanrc.json` in your project root
|
|
151
|
+
- **Global config**: `~/.tokenleanrc.json` in your home directory
|
|
152
|
+
|
|
153
|
+
Project config overrides global config. Both are optional.
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"output": {
|
|
158
|
+
"maxLines": 100,
|
|
159
|
+
"maxTokens": null
|
|
160
|
+
},
|
|
161
|
+
"skipDirs": [
|
|
162
|
+
"generated",
|
|
163
|
+
"vendor"
|
|
164
|
+
],
|
|
165
|
+
"skipExtensions": [
|
|
166
|
+
".gen.ts"
|
|
167
|
+
],
|
|
168
|
+
"importantDirs": [
|
|
169
|
+
"domain",
|
|
170
|
+
"core"
|
|
171
|
+
],
|
|
172
|
+
"importantFiles": [
|
|
173
|
+
"ARCHITECTURE.md"
|
|
174
|
+
],
|
|
175
|
+
"searchPatterns": {
|
|
176
|
+
"hooks": {
|
|
177
|
+
"description": "Find React hooks",
|
|
178
|
+
"pattern": "use[A-Z]\\w+",
|
|
179
|
+
"glob": "**/*.{ts,tsx}"
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
"hotspots": {
|
|
183
|
+
"days": 90
|
|
184
|
+
},
|
|
185
|
+
"structure": {
|
|
186
|
+
"depth": 3
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
```
|
|
190
|
+
|
|
191
|
+
Config values extend built-in defaults (they don't replace them).
|
|
192
|
+
|
|
193
|
+
## Example Workflows
|
|
194
|
+
|
|
195
|
+
### Starting work on an unfamiliar codebase
|
|
196
|
+
|
|
197
|
+
```bash
|
|
198
|
+
tl-structure # Get the lay of the land
|
|
199
|
+
tl-entry # Find entry points
|
|
200
|
+
tl-exports src/lib/ # Understand the public API
|
|
201
|
+
tl-types src/types/ # Understand data shapes
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
### Before refactoring a file
|
|
205
|
+
|
|
206
|
+
```bash
|
|
207
|
+
tl-impact src/core/auth.ts # What would break?
|
|
208
|
+
tl-deps src/core/auth.ts # What does it depend on?
|
|
209
|
+
tl-related src/core/auth.ts # Find the tests
|
|
210
|
+
tl-coverage src/core/auth.ts # Is it well tested?
|
|
211
|
+
tl-complexity src/core/auth.ts # How complex is it?
|
|
212
|
+
```
|
|
213
|
+
|
|
214
|
+
### Understanding a component
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
tl-component src/Button.tsx # Props, hooks, dependencies
|
|
218
|
+
tl-symbols src/Button.tsx # Function signatures
|
|
219
|
+
tl-history src/Button.tsx # Recent changes
|
|
220
|
+
tl-blame src/Button.tsx # Who wrote what
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
### Finding technical debt
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
tl-complexity src/ --threshold 15 # Complex functions
|
|
227
|
+
tl-unused src/ # Dead code
|
|
228
|
+
tl-todo # Outstanding TODOs
|
|
229
|
+
tl-hotspots # Frequently changed (unstable?)
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
## Dependencies
|
|
233
|
+
|
|
234
|
+
- **ripgrep** (`rg`): Required for search-based tools
|
|
235
|
+
- **git**: Required for history/blame/diff tools
|
|
236
|
+
|
|
237
|
+
## Design Principles
|
|
238
|
+
|
|
239
|
+
1. **Single purpose**: Each tool does one thing well
|
|
240
|
+
2. **Minimal output**: Show only what's needed, nothing more
|
|
241
|
+
3. **Token-conscious**: Every tool is designed to save context tokens
|
|
242
|
+
4. **Composable**: Tools work together and support JSON output for piping
|
|
243
|
+
5. **Fast**: No heavy parsing or external services - just regex and file operations
|
|
244
|
+
6. **Universal**: Works with any JavaScript/TypeScript project, most tools support Python/Go too
|
|
245
|
+
|
|
246
|
+
## License
|
|
247
|
+
|
|
248
|
+
MIT
|