@ninjaxtools/slopdex 0.6.0 → 0.8.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/.agents/skills/slopdex/SKILL.md +18 -5
- package/README.md +139 -9
- package/dist/cli.js +1080 -234
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +109 -11
- package/dist/index.js +916 -196
- package/dist/index.js.map +1 -1
- package/package.json +10 -3
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: slopdex
|
|
3
|
-
description: Use when indexing TypeScript or
|
|
3
|
+
description: Use when indexing Python, JavaScript, JSX, TypeScript, TSX, Rust, Go, Java, or C code, running semantic function search, finding duplicate function candidates, or analyzing physical code cohesion with the slopdex command-line tool.
|
|
4
4
|
---
|
|
5
5
|
|
|
6
6
|
# Slopdex CLI
|
|
7
7
|
|
|
8
|
-
Use `slopdex` to index named JavaScript
|
|
8
|
+
Use `slopdex` to index named Python, JavaScript, JSX, TypeScript, TSX, Rust, Go, Java, and C callables with Tree-sitter, search them by meaning, identify similar or duplicated functions, and find related functions scattered across a repository. Languages are detected by extension and can coexist in one index.
|
|
9
9
|
|
|
10
10
|
## Default Workflow
|
|
11
11
|
|
|
@@ -39,6 +39,10 @@ Do not expose API keys in commands, output, configuration files, or commits.
|
|
|
39
39
|
|
|
40
40
|
## Indexing
|
|
41
41
|
|
|
42
|
+
Root and nested `.gitignore` files restrict indexing, including tracked files. Working-tree updates use current ignore files; historical or committed-only Git updates use ignore files from the selected commit. A normal refresh removes newly ignored files from the index. Explicit updates reject ignored paths.
|
|
43
|
+
|
|
44
|
+
Indexing records parse, callable-extraction, file-read, and file-size failures in SQLite while retaining healthy callables. Commands warn on stderr when unresolved diagnostics remain. Inspect them with `slopdex index-errors --format summary` (or JSON by default); this reads saved errors without refreshing the index or calling providers. Records include paths, source locations, recoverable function names, messages, and available source text. `status` reports `indexingErrorCount` and `failedFileCount`. Failed files are retried during updates; fixes, deletions, and exclusions clear their diagnostics. `--ignore-errors` silences diagnostic warnings without discarding the records.
|
|
45
|
+
|
|
42
46
|
If a CLI command cannot find its source index, Slopdex prints a notice to stderr and automatically creates and populates it from committed `HEAD`, then overlays working-tree changes. Missing cross-search target indexes are initialized from the target repository's `HEAD` and working tree as well.
|
|
43
47
|
|
|
44
48
|
Index the current committed snapshot and working-tree overlay:
|
|
@@ -211,7 +215,15 @@ Cross-search excludes one-line callables by default. Raise `--min-lines` for mor
|
|
|
211
215
|
slopdex cross-search --min-lines 4 --threshold 0.9
|
|
212
216
|
```
|
|
213
217
|
|
|
214
|
-
Filter
|
|
218
|
+
Filter source symbols by qualified callable name while searching the whole eligible index:
|
|
219
|
+
|
|
220
|
+
```bash
|
|
221
|
+
slopdex cross-search -e '^(User|Session)\.' --source-path src --threshold 0.9
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
`-e` / `--regexp` uses a case-sensitive JavaScript regex. In cross-search and cohesion, it restricts sources only. Combine it with `--source-path`, `--changed-since`, `--uncommitted`, and other analysis options. When both Git filters are present, sources must have changed since the commit and belong to an uncommitted file. In `search` and `search-summary`, `-e` filters result names before applying `--limit`.
|
|
225
|
+
|
|
226
|
+
To filter both source and matching candidates, use `--regex`:
|
|
215
227
|
|
|
216
228
|
```bash
|
|
217
229
|
slopdex cross-search --regex '^(User|Session)\.' --threshold 0.9
|
|
@@ -253,7 +265,7 @@ Restrict source functions to a file or recursive directory while still matching
|
|
|
253
265
|
slopdex cross-search --source-path src/services --format summary --threshold 0.9
|
|
254
266
|
```
|
|
255
267
|
|
|
256
|
-
`--source-path` restricts only source functions. It can be combined with `--changed-since
|
|
268
|
+
`--source-path` restricts only source functions. It can be combined with `-e`, `--changed-since`, and `--uncommitted`; all supplied restrictions must match.
|
|
257
269
|
|
|
258
270
|
Restrict source functions to additions, modifications, and moves relative to a commit, including current working-tree changes:
|
|
259
271
|
|
|
@@ -320,7 +332,8 @@ Prefer JSON or JSONL when another command will consume the results. Prefer summa
|
|
|
320
332
|
--include-source Include callable source in cohesion JSON
|
|
321
333
|
--cross-file-only Exclude matches from the source file
|
|
322
334
|
--min-lines <number> Minimum cross-search callable length
|
|
323
|
-
--
|
|
335
|
+
-e, --regexp <regex> Match qualified symbols (analysis: sources only)
|
|
336
|
+
--regex <regex> Match both analysis source and candidate names
|
|
324
337
|
--target-config <path> Target repository configuration file
|
|
325
338
|
```
|
|
326
339
|
|
package/README.md
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
1
|
# slopdex
|
|
2
2
|
|
|
3
|
-
Slopdex
|
|
4
|
-
|
|
5
|
-
Supported file types are `.ts`, `.tsx`, `.mts`, `.cts`, `.js`, `.jsx`, `.mjs`, and `.cjs`.
|
|
6
|
-
|
|
7
|
-
## Requirements
|
|
8
|
-
|
|
9
|
-
- Node.js 24 or later
|
|
10
|
-
- An OpenAI or Jina AI API key
|
|
3
|
+
Slopdex uses Tree-sitter to index named functions in Python, JavaScript, JSX, TypeScript, TSX, Rust, Go, Java, and C repositories. It uses embeddings to search code by meaning, find similar implementations, and measure whether related functions are stored near each other.
|
|
11
4
|
|
|
12
5
|
## Install
|
|
13
6
|
|
|
@@ -31,6 +24,45 @@ slopdex search "validate an authenticated session" --format summary --limit 10
|
|
|
31
24
|
|
|
32
25
|
## Analysis Examples
|
|
33
26
|
|
|
27
|
+
### Search By Function Purpose
|
|
28
|
+
|
|
29
|
+
Enable optional purpose summaries for every indexed callable:
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
slopdex use-summaries
|
|
33
|
+
slopdex search-summary "keep the repository index synchronized" --limit 10 --format summary
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Summaries describe a function's responsibility and role in its codebase, using its repository name, path, source, and surrounding file context. Generation uses the OpenAI Responses API with **`gpt-5.6-sol`** by default and requires `OPENAI_API_KEY`, including when Jina supplies the embeddings.
|
|
37
|
+
|
|
38
|
+
`use-summaries` stores each summary and its embedding in SQLite and enables a persistent repository-index setting. Subsequent indexing operations automatically generate summaries for new and changed files, including changes to surrounding context and file paths. Unchanged inputs reuse cached summaries and vectors; deleted functions disappear from summary search. Running `use-summaries` again is a no-op when summaries are already complete. Summary generation and embeddings are saved atomically, so a failed request does not leave partially updated callables.
|
|
39
|
+
|
|
40
|
+
`search-summary` uses a separate summary embedding store with the configured embedding provider and supports the same query, limit, threshold, and output options as `search`. JSON results include the summary; `--format summary` prints it alongside each match. `status` reports `summariesEnabled`, `summaryCount`, and `summaryProfile`.
|
|
41
|
+
|
|
42
|
+
To choose a different summary model, run `slopdex use-summaries --summary-model <model-id>` or set `summaryModel` in `.slopdex/config.json`. The chosen model is persisted for future updates. Existing indexes migrate automatically; summaries remain disabled until enabled explicitly.
|
|
43
|
+
|
|
44
|
+
### Combined Code And Purpose Analysis
|
|
45
|
+
|
|
46
|
+
Once summaries are enabled and every indexed callable has a summary embedding, `cross-search` and `cohesion` automatically combine implementation and purpose similarity:
|
|
47
|
+
|
|
48
|
+
```text
|
|
49
|
+
similarity = 0.5 * codeSimilarity + 0.5 * summarySimilarity
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
slopdex use-summaries
|
|
54
|
+
slopdex cross-search --threshold 0.8 --format json
|
|
55
|
+
slopdex cohesion --threshold 0.8 --format summary
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Both cosine scores and their average are calculated in one SQLite query. Thresholds (including half-open ranges), ranking, and neighbor/result limits apply to the combined score. Cohesion uses these combined neighbors for reciprocity, gap scores, file affinities, and groups.
|
|
59
|
+
|
|
60
|
+
For cross-repository search, both indexes must have complete, enabled summaries. If either index lacks them, the entire analysis uses code-only similarity. Cohesion likewise uses code-only scoring if its summary index is incomplete or disabled. The existing embedding profiles must match across repositories; summary-generator models may differ.
|
|
61
|
+
|
|
62
|
+
Combined JSON matches and cohesion pairs expose `codeSimilarity` and `summarySimilarity` alongside `similarity`. Cross-search rows include a `scoring` object with `similarityMode`, `similarityWeights`, and both summary-generator profiles. Cohesion records the mode and weights in `parameters` and the summary-generator profile in `repository.summaryProfile`. The mode is `"code-summary-average"` with weights `{ "code": 0.5, "summary": 0.5 }`, or `"code"` with weights `{ "code": 1, "summary": 0 }`. Text output labels combined scores.
|
|
63
|
+
|
|
64
|
+
Compare analysis results only when the similarity mode and weights match, as well as the embedding profile, summary-generator profiles, thresholds, and analysis scope. Enabling summaries can change rankings and cohesion metrics. `search` continues to use only code vectors, and `search-summary` uses only summary vectors.
|
|
65
|
+
|
|
34
66
|
### Duplicate Analysis
|
|
35
67
|
|
|
36
68
|
Compare functions in different files and include functions that span at least four lines:
|
|
@@ -77,7 +109,7 @@ Cohesion: 184 functions analyzed, 37 semantic edges
|
|
|
77
109
|
|
|
78
110
|
The summary divides semantic relationships into the same file, the same folder, and different folders. Mean distance increases when related functions are stored farther apart. The gap score combines semantic similarity with path distance and ranks pairs for review. `reciprocal` means both functions are among each other's nearest semantic matches.
|
|
79
111
|
|
|
80
|
-
Cohesion does not have a universal pass threshold. Compare results only when the embedding
|
|
112
|
+
Cohesion does not have a universal pass threshold. Compare results only when the similarity mode and weights, embedding and summary-generator profiles, threshold, neighbor count, and source scope are the same.
|
|
81
113
|
|
|
82
114
|
## Limit Analysis Scope
|
|
83
115
|
|
|
@@ -104,10 +136,39 @@ slopdex cohesion --uncommitted --format summary
|
|
|
104
136
|
|
|
105
137
|
These options restrict the source functions. Slopdex still compares them with the full index.
|
|
106
138
|
|
|
139
|
+
Filter source symbols by qualified name with `-e <regex>` (or `--regexp <regex>`):
|
|
140
|
+
|
|
141
|
+
```bash
|
|
142
|
+
slopdex cross-search -e '^UserService\.' --format summary
|
|
143
|
+
slopdex cohesion -e 'validate|authenticate' --source-path src/auth
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The regex uses case-sensitive JavaScript syntax and matches qualified names such as `UserService.authenticate`. It filters only the source symbols for cross-search and cohesion; matching candidates are still drawn from the whole eligible index, including symbols that do not match the regex. It works with code-only and combined code/summary scoring.
|
|
147
|
+
|
|
148
|
+
Source restrictions combine by intersection:
|
|
149
|
+
|
|
150
|
+
```bash
|
|
151
|
+
slopdex cross-search -e 'validate' \
|
|
152
|
+
--source-path src \
|
|
153
|
+
--changed-since origin/main \
|
|
154
|
+
--uncommitted \
|
|
155
|
+
--min-lines 4 \
|
|
156
|
+
--cross-file-only
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
With both Git filters, a source must have changed since the specified commit and belong to an uncommitted file. Path, name, and minimum-line filters narrow the selection further. Existing target restrictions such as `--min-lines` and `--cross-file-only` continue to apply. The separate `--regex` option filters **both** analysis sources and matching candidates.
|
|
160
|
+
|
|
107
161
|
## Output And Filters
|
|
108
162
|
|
|
109
163
|
`search` supports `json` and `summary` output. `cross-search` supports `json`, `summary`, and `clusters` output. Use `--format` to select one.
|
|
110
164
|
|
|
165
|
+
For `search` and `search-summary`, `-e` restricts result symbols before the result limit is applied:
|
|
166
|
+
|
|
167
|
+
```bash
|
|
168
|
+
slopdex search "validate session" -e '^Session\.' --limit 10
|
|
169
|
+
slopdex search-summary "persist user data" -e 'save|persist' --limit 5
|
|
170
|
+
```
|
|
171
|
+
|
|
111
172
|
Use `--threshold` with a minimum similarity or a range:
|
|
112
173
|
|
|
113
174
|
```bash
|
|
@@ -121,6 +182,34 @@ Run `slopdex --help` for all commands and options.
|
|
|
121
182
|
|
|
122
183
|
## Indexing And Data
|
|
123
184
|
|
|
185
|
+
### Supported Languages
|
|
186
|
+
|
|
187
|
+
Languages are detected automatically from file extensions. A single index can contain multiple languages; search, purpose summaries, cross-search, and cohesion work across all of them.
|
|
188
|
+
|
|
189
|
+
| Language | Extensions | Extracted callables |
|
|
190
|
+
| --- | --- | --- |
|
|
191
|
+
| Python | `.py`, `.pyw` | Functions, async functions, class methods, constructors, generators, and bound lambdas; includes decorators in source |
|
|
192
|
+
| JavaScript | `.js`, `.mjs`, `.cjs` | Functions, generators, methods, constructors, and named function expressions/arrows |
|
|
193
|
+
| JSX | `.jsx` | JavaScript callables, including components returning JSX |
|
|
194
|
+
| TypeScript | `.ts`, `.mts`, `.cts` | Typed functions, methods, constructors, and named function expressions/arrows |
|
|
195
|
+
| TSX | `.tsx` | TypeScript callables, including generic components returning JSX |
|
|
196
|
+
| Rust | `.rs` | Functions, `impl` methods/associated functions, trait default methods, and `let`-bound closures |
|
|
197
|
+
| Go | `.go` | Functions, receiver methods, and function literals bound to variables or assignments |
|
|
198
|
+
| Java | `.java` | Methods, constructors (including compact record constructors), and variable-bound lambdas |
|
|
199
|
+
| C | `.c`, `.h` | Function definitions, including static/inline functions and functions returning pointers |
|
|
200
|
+
|
|
201
|
+
Qualified names include enclosing classes, functions, and explicit modules. Go methods include their receiver type (`Store[T].Get`); Rust trait implementations include the type and trait (`<Store<T> as Read>.read`). Definitions retain their source, signature, line/column locations, and stable identity for incremental updates. Declarations without bodies and anonymous callbacks are omitted. Extraction is syntactic: Rust macros and C macros are not expanded, and C preprocessor branches are indexed as written. `.h` files use the C grammar.
|
|
202
|
+
|
|
203
|
+
Tree-sitter grammars ship as package dependencies; no language server or project compiler configuration is required. Syntax errors produce warnings while recoverable callables are still indexed. Existing indexes pick up newly supported files during the next normal refresh.
|
|
204
|
+
|
|
205
|
+
Default exclusions cover dependency and build directories: `.git`, `.slopdex`, `node_modules`, `dist`, `build`, `coverage`, `vendor`, `generated`, `.venv`, `venv`, `__pycache__`, `.tox`, `.mypy_cache`, `.pytest_cache`, and `target`. Optional `include` and `exclude` glob arrays in `.slopdex/config.json` further restrict the indexed files.
|
|
206
|
+
|
|
207
|
+
Slopdex also respects root and nested `.gitignore` files using the [`ignore`](https://www.npmjs.com/package/ignore) package. Patterns, directory rules, anchoring, escapes, and `!` exceptions follow Git ignore semantics. A nested rule cannot re-include files beneath an excluded parent directory. These exclusions apply even to tracked files and when Git is unavailable; explicit `update-files` requests for ignored files are rejected.
|
|
208
|
+
|
|
209
|
+
Working-tree indexing and HEAD overlays use the current `.gitignore` files. Historical snapshots and committed-only Git indexing use the ignore files stored in the selected commit. Normal refreshes remove previously indexed files that become ignored and discover files that become eligible again, including when only ignore rules change. Configuration includes and negated ignore rules cannot override the built-in exclusions.
|
|
210
|
+
|
|
211
|
+
### Index Updates
|
|
212
|
+
|
|
124
213
|
Before each analysis command, Slopdex updates its index from the current Git commit and the staged, unstaged, and untracked files in the working tree. The index is created at `.slopdex/index.sqlite` by default.
|
|
125
214
|
|
|
126
215
|
Add `.slopdex/` to the repository's `.gitignore` so the local index is not committed.
|
|
@@ -129,6 +218,27 @@ Slopdex sends extracted function source to the configured embedding provider. Th
|
|
|
129
218
|
|
|
130
219
|
Whole-repository cohesion analysis compares neighbors for every selected function. Use `--source-path`, `--changed-since`, or `--uncommitted` to reduce the scope in large repositories.
|
|
131
220
|
|
|
221
|
+
### Inspecting Indexing Errors
|
|
222
|
+
|
|
223
|
+
Slopdex persists file and function indexing diagnostics in the SQLite `indexing_errors` table. Parse errors, parser exceptions, callable-extraction failures, file-read failures, and files exceeding `maxFileSize` retain references instead of silently disappearing. Healthy functions in partially parsed files and other healthy files remain searchable; malformed callables are omitted from semantic search and listed in the diagnostics.
|
|
224
|
+
|
|
225
|
+
```bash
|
|
226
|
+
slopdex index-errors
|
|
227
|
+
slopdex index-errors --format summary
|
|
228
|
+
slopdex index-errors --index /path/to/another/index.sqlite
|
|
229
|
+
```
|
|
230
|
+
|
|
231
|
+
This command reads the saved diagnostics without refreshing the index or calling an embedding/summary provider, so it works without API credentials. JSON includes the path, language, error code and message, file/function scope, recovered qualified name when available, line/column ranges, available source text, and Git/working-tree provenance. If Tree-sitter cannot identify a function, the unparsed region is still retained as a file diagnostic.
|
|
232
|
+
|
|
233
|
+
Every invocation warns on stderr while saved errors remain, including cached runs and cross-search target indexes. Suppress this warning with `--ignore-errors`:
|
|
234
|
+
|
|
235
|
+
```bash
|
|
236
|
+
slopdex cross-search --ignore-errors
|
|
237
|
+
slopdex index-errors --format summary --ignore-errors
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
Silencing warnings does not delete diagnostics. `status` reports `indexingErrorCount` and `failedFileCount`; `functionCount` counts searchable callables. Normal updates retry failed files, including unchanged Git blobs. Errors clear when a file is successfully indexed, deleted, or excluded. Existing indexes migrate automatically and rescan once on their next full update to detect previously unreported parse failures. Diagnostics are committed atomically with the corresponding file update.
|
|
241
|
+
|
|
132
242
|
## Library
|
|
133
243
|
|
|
134
244
|
The package also exports the index and analysis APIs:
|
|
@@ -156,12 +266,32 @@ index.close();
|
|
|
156
266
|
|
|
157
267
|
Exports also include `crossSearch`, `analyzeCohesion`, `JinaEmbeddingProvider`, and standalone functions for index updates and searches.
|
|
158
268
|
|
|
269
|
+
Library callers can set `sourceFilter.nameRegex` on cross-search/cohesion options for source-only filtering, together with `path` and the Git filter type. A `changed-since` filter also accepts `uncommitted: true`. Query searches accept `nameRegex` in `SimilaritySearchOptions` to filter result symbols. Cohesion reports record source restrictions in `parameters.sourceFilter` and label filtered analyses as `selected-sources`.
|
|
270
|
+
|
|
271
|
+
Use `index.indexErrors()` to inspect diagnostics through an open index, or the exported `readIndexErrors(indexPath)` to inspect a saved database without a provider. Error records use the exported `IndexingError` type.
|
|
272
|
+
|
|
273
|
+
For summary search, call `await index.useSummaries()` after updating the index, then `await index.searchSummary({ query: "maintain the repository index" })`. Optionally pass `summaryProvider: new OpenAISummaryProvider({ model: "gpt-5.6-sol" })` when opening an index. Custom providers implement the exported `SummaryProvider` interface. The package also exports standalone `useSummaries` and `searchSummary` helpers.
|
|
274
|
+
|
|
159
275
|
## Development
|
|
160
276
|
|
|
161
277
|
```bash
|
|
162
278
|
npm run check
|
|
163
279
|
```
|
|
164
280
|
|
|
281
|
+
To cross-check the shared-language fixtures against a built sibling checkout of `treesitter-index`, run:
|
|
282
|
+
|
|
283
|
+
```bash
|
|
284
|
+
npm run check:parser-parity
|
|
285
|
+
# Or provide another reference executable:
|
|
286
|
+
npm run check:parser-parity -- /path/to/treesitter-index
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
The default reference is `../treesitter-index/target/debug/treesitter-index`. The check covers eight shared languages; that project has no C grammar. Callable regression tests also run as part of `npm run check` without requiring the sibling checkout.
|
|
290
|
+
|
|
291
|
+
The projects index different information: `treesitter-index` includes declarations, types, imports, and `.pyi` stubs, while Slopdex indexes callable implementations (including nested callables and bound closures). Slopdex also supports `.pyw` and C. Its native Node grammar versions are pinned for compatibility with `tree-sitter@0.21`; the reference uses newer Python and Rust grammars. In particular, Rust `unsafe extern` blocks and async closures currently produce syntax-recovery warnings in Slopdex, so those cases are not covered by the passing parity fixtures.
|
|
292
|
+
|
|
293
|
+
After upgrading parser behavior, explicitly reparse previously indexed files with `slopdex update-files <path...>` to refresh their symbols, signatures, and embeddings even when the file contents are unchanged.
|
|
294
|
+
|
|
165
295
|
## Configuration
|
|
166
296
|
|
|
167
297
|
Configuration is optional. Without `.slopdex/config.json`, Slopdex uses OpenAI's `text-embedding-3-large` model with 3072 dimensions and the built-in source exclusions.
|