@better-vibe/repo-slice 1.0.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/LICENSE +21 -0
- package/README.md +374 -0
- package/dist/cli.js +190243 -0
- package/package.json +68 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Better Vibe
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,374 @@
|
|
|
1
|
+
# repo-slice
|
|
2
|
+
|
|
3
|
+
A deterministic CLI that extracts high-signal context bundles from repositories for AI-assisted coding workflows.
|
|
4
|
+
|
|
5
|
+
## Overview
|
|
6
|
+
|
|
7
|
+
`repo-slice` analyzes your codebase and produces focused, relevant context bundles optimized for LLMs. It follows import graphs, finds symbol references, and intelligently selects the most relevant code within configurable budgets.
|
|
8
|
+
|
|
9
|
+
**Key Features:**
|
|
10
|
+
- **Multiple anchor types** - Entry files, symbols, git diffs, or error logs
|
|
11
|
+
- **Import graph traversal** - Automatically includes dependencies up to N levels deep
|
|
12
|
+
- **Budget-aware selection** - Stay within character/token limits with smart ranking
|
|
13
|
+
- **Deterministic output** - Same inputs always produce the same bundle
|
|
14
|
+
- **Monorepo support** - Workspace detection and scoped queries
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
### From npm (recommended)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
npm install -g repo-slice
|
|
22
|
+
bun install -g repo-slice
|
|
23
|
+
# or
|
|
24
|
+
npx repo-slice pack --entry src/index.ts
|
|
25
|
+
bunx repo-slice pack --entry src/index.ts
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
### From source
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# Clone and install
|
|
32
|
+
git clone https://github.com/your-org/repo-slice.git
|
|
33
|
+
cd repo-slice
|
|
34
|
+
bun install
|
|
35
|
+
|
|
36
|
+
# Build
|
|
37
|
+
bun run build
|
|
38
|
+
|
|
39
|
+
# Run directly with bun (development)
|
|
40
|
+
bun run src/cli.ts
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
**Requirements:**
|
|
44
|
+
- Node.js >= 18 (Node.js 20 LTS recommended)
|
|
45
|
+
- Bun (for development)
|
|
46
|
+
|
|
47
|
+
## Quick Start
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
# Bundle context starting from an entry file
|
|
51
|
+
repo-slice pack --entry src/index.ts
|
|
52
|
+
|
|
53
|
+
# Find all code related to a symbol
|
|
54
|
+
repo-slice pack --symbol handleRequest
|
|
55
|
+
|
|
56
|
+
# Bundle files changed in a git diff
|
|
57
|
+
repo-slice pack --from-diff HEAD~3..HEAD
|
|
58
|
+
|
|
59
|
+
# Parse error logs and bundle relevant code
|
|
60
|
+
repo-slice pack --from-log build-errors.txt
|
|
61
|
+
|
|
62
|
+
# Output as JSON instead of Markdown
|
|
63
|
+
repo-slice pack --entry src/app.ts --format json
|
|
64
|
+
|
|
65
|
+
# Save to file
|
|
66
|
+
repo-slice pack --entry src/api.ts --out context.md
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Commands
|
|
70
|
+
|
|
71
|
+
### `repo-slice pack [options]`
|
|
72
|
+
|
|
73
|
+
Extract a context bundle from the repository.
|
|
74
|
+
|
|
75
|
+
#### Anchor Options (at least one required)
|
|
76
|
+
|
|
77
|
+
| Option | Description |
|
|
78
|
+
|--------|-------------|
|
|
79
|
+
| `--entry <path>` | Add entry file as anchor (repeatable) |
|
|
80
|
+
| `--symbol <query>` | Add symbol query as anchor (repeatable) |
|
|
81
|
+
| `--from-diff <revRange>` | Use git diff hunks as anchors (e.g., `HEAD~3..HEAD`) |
|
|
82
|
+
| `--from-log <path>` | Parse error log file for file:line anchors |
|
|
83
|
+
|
|
84
|
+
#### Symbol Options
|
|
85
|
+
|
|
86
|
+
| Option | Description |
|
|
87
|
+
|--------|-------------|
|
|
88
|
+
| `--symbol-strict` | Fail if any symbol resolves to multiple definitions |
|
|
89
|
+
|
|
90
|
+
**Symbol query formats:**
|
|
91
|
+
- `functionName` - Find by name across all files
|
|
92
|
+
- `ClassName.methodName` - Find class method
|
|
93
|
+
- `path/to/file.ts:symbolName` - File-hint syntax for disambiguation
|
|
94
|
+
- `module.name:SymbolName` - Python module-qualified lookup
|
|
95
|
+
|
|
96
|
+
#### Workspace Options
|
|
97
|
+
|
|
98
|
+
| Option | Description |
|
|
99
|
+
|--------|-------------|
|
|
100
|
+
| `--workspace <name\|path>` | Scope to specific workspace |
|
|
101
|
+
| `--all-workspaces` | Include all workspaces |
|
|
102
|
+
| `--fallback-all` | Retry across all workspaces if symbol not found |
|
|
103
|
+
|
|
104
|
+
#### Budget & Depth Options
|
|
105
|
+
|
|
106
|
+
| Option | Description | Default |
|
|
107
|
+
|--------|-------------|---------|
|
|
108
|
+
| `--depth <n>` | Import graph traversal depth | `2` |
|
|
109
|
+
| `--budget-chars <n>` | Maximum characters in output | `28000` |
|
|
110
|
+
| `--budget-tokens <n>` | Maximum tokens (estimated) | - |
|
|
111
|
+
| `--include-tests <auto\|true\|false>` | Include test files | `auto` |
|
|
112
|
+
|
|
113
|
+
#### Output Options
|
|
114
|
+
|
|
115
|
+
| Option | Description |
|
|
116
|
+
|--------|-------------|
|
|
117
|
+
| `--format <md\|json>` | Output format |
|
|
118
|
+
| `--out <path>` | Write to file instead of stdout |
|
|
119
|
+
| `--reason` | Include selection reasons in output |
|
|
120
|
+
| `--redact` | Redact secrets (API keys, etc.) |
|
|
121
|
+
| `--no-timestamp` | Omit timestamp for reproducible output |
|
|
122
|
+
| `--debug` | Enable debug logging |
|
|
123
|
+
|
|
124
|
+
### `repo-slice workspaces`
|
|
125
|
+
|
|
126
|
+
List detected workspaces in the repository.
|
|
127
|
+
|
|
128
|
+
```bash
|
|
129
|
+
$ repo-slice workspaces
|
|
130
|
+
packages/web node /path/to/repo/packages/web
|
|
131
|
+
packages/api node /path/to/repo/packages/api
|
|
132
|
+
services/ml python /path/to/repo/services/ml
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
### `repo-slice version`
|
|
136
|
+
|
|
137
|
+
Print the version number.
|
|
138
|
+
|
|
139
|
+
## Examples
|
|
140
|
+
|
|
141
|
+
### Basic Entry File Bundle
|
|
142
|
+
|
|
143
|
+
```bash
|
|
144
|
+
repo-slice pack --entry src/server.ts
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Produces a bundle containing `src/server.ts` and its imports (up to depth 2).
|
|
148
|
+
|
|
149
|
+
### Symbol Search with References
|
|
150
|
+
|
|
151
|
+
```bash
|
|
152
|
+
repo-slice pack --symbol handleAuth --reason
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
Finds all definitions of `handleAuth`, their references, and includes reasoning for each file's inclusion.
|
|
156
|
+
|
|
157
|
+
### Debugging Build Errors
|
|
158
|
+
|
|
159
|
+
```bash
|
|
160
|
+
# Save TypeScript errors to a file
|
|
161
|
+
tsc --noEmit 2>&1 | tee errors.txt
|
|
162
|
+
|
|
163
|
+
# Bundle the relevant code
|
|
164
|
+
repo-slice pack --from-log errors.txt --out context.md
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
Supported log formats:
|
|
168
|
+
- **TypeScript/tsc**: `src/file.ts:10:5 - error TS2345: ...`
|
|
169
|
+
- **Jest/Vitest**: `FAIL src/file.test.ts` or stack traces
|
|
170
|
+
- **pytest**: `File "src/file.py", line 10`
|
|
171
|
+
- **mypy**: `src/file.py:10: error: ...`
|
|
172
|
+
- **pyright**: `src/file.py:10:5 - error: ...`
|
|
173
|
+
|
|
174
|
+
### Code Review Context
|
|
175
|
+
|
|
176
|
+
```bash
|
|
177
|
+
# Get context for a PR
|
|
178
|
+
repo-slice pack --from-diff origin/main..HEAD --reason
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
### Strict Symbol Resolution
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
repo-slice pack --symbol Config --symbol-strict
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
If `Config` is defined in multiple files, this will fail with a helpful message:
|
|
188
|
+
|
|
189
|
+
```
|
|
190
|
+
Ambiguous symbol(s) found (--symbol-strict enabled):
|
|
191
|
+
Config:
|
|
192
|
+
- src/config/app.ts:15
|
|
193
|
+
- src/config/db.ts:8
|
|
194
|
+
Use file-hint syntax (e.g., path/to/file.ts:SymbolName) to disambiguate.
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
Then disambiguate:
|
|
198
|
+
|
|
199
|
+
```bash
|
|
200
|
+
repo-slice pack --symbol "src/config/app.ts:Config"
|
|
201
|
+
```
|
|
202
|
+
|
|
203
|
+
### JSON Output for Tooling
|
|
204
|
+
|
|
205
|
+
```bash
|
|
206
|
+
repo-slice pack --entry src/api.ts --format json | jq '.items[].filePath'
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
### Monorepo Usage
|
|
210
|
+
|
|
211
|
+
```bash
|
|
212
|
+
# List workspaces
|
|
213
|
+
repo-slice workspaces
|
|
214
|
+
|
|
215
|
+
# Bundle from specific workspace
|
|
216
|
+
repo-slice pack --entry packages/web/src/index.ts --workspace packages/web
|
|
217
|
+
|
|
218
|
+
# Search symbol across all workspaces
|
|
219
|
+
repo-slice pack --symbol sharedUtil --all-workspaces
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
## Configuration
|
|
223
|
+
|
|
224
|
+
Create `.repo-slicerc.json` at your repository root or workspace root:
|
|
225
|
+
|
|
226
|
+
```json
|
|
227
|
+
{
|
|
228
|
+
"budgetChars": 28000,
|
|
229
|
+
"depth": 2,
|
|
230
|
+
"includeTests": "auto",
|
|
231
|
+
"ignore": [
|
|
232
|
+
"**/dist/**",
|
|
233
|
+
"**/build/**",
|
|
234
|
+
"**/*.min.js",
|
|
235
|
+
"**/node_modules/**"
|
|
236
|
+
],
|
|
237
|
+
"workspaces": {
|
|
238
|
+
"mode": "auto",
|
|
239
|
+
"pythonImportRoots": ["src", "."]
|
|
240
|
+
},
|
|
241
|
+
"redact": {
|
|
242
|
+
"enabled": false,
|
|
243
|
+
"patterns": [
|
|
244
|
+
"(?i)(api[_-]?key|apikey)\\s*[:=]\\s*['\"][^'\"]+['\"]",
|
|
245
|
+
"(?i)(secret|password|token)\\s*[:=]\\s*['\"][^'\"]+['\"]",
|
|
246
|
+
"AKIA[0-9A-Z]{16}",
|
|
247
|
+
"-----BEGIN (RSA |EC |DSA |OPENSSH )?PRIVATE KEY-----"
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
### Configuration Options
|
|
254
|
+
|
|
255
|
+
| Option | Type | Default | Description |
|
|
256
|
+
|--------|------|---------|-------------|
|
|
257
|
+
| `budgetChars` | number | `28000` | Default character budget |
|
|
258
|
+
| `depth` | number | `2` | Default import traversal depth |
|
|
259
|
+
| `includeTests` | string | `"auto"` | Test file inclusion: `auto`, `true`, `false` |
|
|
260
|
+
| `ignore` | string[] | See below | Glob patterns to ignore |
|
|
261
|
+
| `workspaces.mode` | string | `"auto"` | Workspace detection: `auto`, `all`, or workspace name |
|
|
262
|
+
| `workspaces.pythonImportRoots` | string[] | `["src", "."]` | Python import resolution roots |
|
|
263
|
+
| `redact.enabled` | boolean | `false` | Enable secret redaction |
|
|
264
|
+
| `redact.patterns` | string[] | See above | Regex patterns for redaction |
|
|
265
|
+
|
|
266
|
+
**Default ignore patterns:**
|
|
267
|
+
```json
|
|
268
|
+
["**/dist/**", "**/build/**", "**/.next/**", "**/__snapshots__/**"]
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
## Output Formats
|
|
272
|
+
|
|
273
|
+
### Markdown (default)
|
|
274
|
+
|
|
275
|
+
```markdown
|
|
276
|
+
# repo-slice bundle
|
|
277
|
+
|
|
278
|
+
- command: repo-slice pack --entry src/index.ts
|
|
279
|
+
- scope: nearest (packages/web)
|
|
280
|
+
- budget: 15234/28000 chars
|
|
281
|
+
|
|
282
|
+
## Index
|
|
283
|
+
- file src/index.ts (reasons: entry file)
|
|
284
|
+
- file src/utils/helpers.ts (reasons: imported by src/index.ts)
|
|
285
|
+
|
|
286
|
+
## Content
|
|
287
|
+
### file src/index.ts (full file)
|
|
288
|
+
workspace: packages/web
|
|
289
|
+
reasons: entry file
|
|
290
|
+
|
|
291
|
+
\`\`\`ts
|
|
292
|
+
import { helper } from './utils/helpers';
|
|
293
|
+
// ... file content
|
|
294
|
+
\`\`\`
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
### JSON
|
|
298
|
+
|
|
299
|
+
```json
|
|
300
|
+
{
|
|
301
|
+
"meta": {
|
|
302
|
+
"command": "repo-slice pack --entry src/index.ts",
|
|
303
|
+
"scope": { "mode": "nearest", "workspaces": ["packages/web"] },
|
|
304
|
+
"budget": { "chars": 28000, "usedChars": 15234 }
|
|
305
|
+
},
|
|
306
|
+
"items": [
|
|
307
|
+
{
|
|
308
|
+
"kind": "file",
|
|
309
|
+
"filePath": "src/index.ts",
|
|
310
|
+
"content": "import { helper } from './utils/helpers';...",
|
|
311
|
+
"reasons": ["entry file"]
|
|
312
|
+
}
|
|
313
|
+
],
|
|
314
|
+
"omitted": []
|
|
315
|
+
}
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
## Supported Languages
|
|
319
|
+
|
|
320
|
+
| Language | Parser | Features |
|
|
321
|
+
|----------|--------|----------|
|
|
322
|
+
| TypeScript | TypeScript Compiler API | Full import resolution, symbol lookup, references |
|
|
323
|
+
| JavaScript | TypeScript Compiler API | Full import resolution, symbol lookup, references |
|
|
324
|
+
| Python | tree-sitter | Import resolution, function/class definitions, references |
|
|
325
|
+
|
|
326
|
+
## How It Works
|
|
327
|
+
|
|
328
|
+
1. **Anchor Resolution** - Entry files, symbols, diff hunks, or log entries become starting points
|
|
329
|
+
2. **Import Graph Traversal** - Follow imports up to `--depth` levels
|
|
330
|
+
3. **Candidate Scoring** - Each file/snippet gets a relevance score based on:
|
|
331
|
+
- Anchor type (symbols: 1000, diagnostics: 950, diffs: 850, entries: 800)
|
|
332
|
+
- Distance from anchors (closer = higher score)
|
|
333
|
+
- File size penalty (larger files score lower)
|
|
334
|
+
4. **Budget Selection** - Top-ranked candidates selected within budget
|
|
335
|
+
5. **Output Generation** - Markdown or JSON bundle with optional reasoning
|
|
336
|
+
|
|
337
|
+
## Exit Codes
|
|
338
|
+
|
|
339
|
+
| Code | Meaning |
|
|
340
|
+
|------|---------|
|
|
341
|
+
| 0 | Success |
|
|
342
|
+
| 1 | Runtime error |
|
|
343
|
+
| 2 | Anchor resolution failure (symbol not found, ambiguous symbol in strict mode) |
|
|
344
|
+
| 3 | Invalid CLI usage |
|
|
345
|
+
|
|
346
|
+
## Caching
|
|
347
|
+
|
|
348
|
+
`repo-slice` caches import graphs and symbol indices in `.repo-slice/cache/` for faster subsequent runs. The cache is automatically invalidated when:
|
|
349
|
+
- Files are modified (mtime/size change)
|
|
350
|
+
- Configuration changes
|
|
351
|
+
- Package version changes
|
|
352
|
+
|
|
353
|
+
## Limitations
|
|
354
|
+
|
|
355
|
+
- **Python references**: Uses name-based matching, may include false positives
|
|
356
|
+
- **Token budgeting**: Uses `chars / 4` estimate, not a real tokenizer
|
|
357
|
+
- **Log parsing**: Limited to TypeScript, Jest, Vitest, pytest, mypy, pyright formats
|
|
358
|
+
|
|
359
|
+
## Development
|
|
360
|
+
|
|
361
|
+
```bash
|
|
362
|
+
# Run tests
|
|
363
|
+
bun test
|
|
364
|
+
|
|
365
|
+
# Run in development
|
|
366
|
+
bun run src/cli.ts pack --entry src/cli.ts
|
|
367
|
+
|
|
368
|
+
# Build for distribution
|
|
369
|
+
bun run build
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## License
|
|
373
|
+
|
|
374
|
+
MIT
|