scip-cli 1.0.0__tar.gz
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.
- scip_cli-1.0.0/LICENSE +21 -0
- scip_cli-1.0.0/MANIFEST.in +4 -0
- scip_cli-1.0.0/PKG-INFO +154 -0
- scip_cli-1.0.0/README.md +130 -0
- scip_cli-1.0.0/pyproject.toml +10 -0
- scip_cli-1.0.0/scip_cli/SKILL.md +76 -0
- scip_cli-1.0.0/scip_cli/__init__.py +2 -0
- scip_cli-1.0.0/scip_cli/__main__.py +70 -0
- scip_cli-1.0.0/scip_cli/commands/__init__.py +1 -0
- scip_cli-1.0.0/scip_cli/commands/def_cmd.py +50 -0
- scip_cli-1.0.0/scip_cli/commands/members.py +84 -0
- scip_cli-1.0.0/scip_cli/commands/rdeps.py +52 -0
- scip_cli-1.0.0/scip_cli/commands/refs.py +107 -0
- scip_cli-1.0.0/scip_cli/commands/search.py +120 -0
- scip_cli-1.0.0/scip_cli/commands/skill.py +24 -0
- scip_cli-1.0.0/scip_cli/commands/symbols.py +42 -0
- scip_cli-1.0.0/scip_cli/lib.py +369 -0
- scip_cli-1.0.0/scip_cli.egg-info/PKG-INFO +154 -0
- scip_cli-1.0.0/scip_cli.egg-info/SOURCES.txt +23 -0
- scip_cli-1.0.0/scip_cli.egg-info/dependency_links.txt +1 -0
- scip_cli-1.0.0/scip_cli.egg-info/entry_points.txt +2 -0
- scip_cli-1.0.0/scip_cli.egg-info/top_level.txt +1 -0
- scip_cli-1.0.0/setup.cfg +4 -0
- scip_cli-1.0.0/setup.py +31 -0
- scip_cli-1.0.0/tests/test_pure_functions.py +121 -0
scip_cli-1.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ariel Flesler
|
|
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.
|
scip_cli-1.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: scip-cli
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: Fast code intelligence via SCIP indexes
|
|
5
|
+
Home-page: https://github.com/flesler/scip-cli
|
|
6
|
+
Author: Ariel Flesler
|
|
7
|
+
License: MIT
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Classifier: Topic :: Software Development :: Code Generators
|
|
12
|
+
Requires-Python: >=3.7
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
License-File: LICENSE
|
|
15
|
+
Dynamic: author
|
|
16
|
+
Dynamic: classifier
|
|
17
|
+
Dynamic: description
|
|
18
|
+
Dynamic: description-content-type
|
|
19
|
+
Dynamic: home-page
|
|
20
|
+
Dynamic: license
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
Dynamic: requires-python
|
|
23
|
+
Dynamic: summary
|
|
24
|
+
|
|
25
|
+
# scip-cli
|
|
26
|
+
|
|
27
|
+
[](https://badge.fury.io/py/scip-cli)
|
|
28
|
+
[](https://opensource.org/licenses/MIT)
|
|
29
|
+
|
|
30
|
+
Fast code intelligence CLI for TypeScript/JavaScript projects. Query SCIP indexes directly via SQLite for instant results.
|
|
31
|
+
|
|
32
|
+
## Features
|
|
33
|
+
|
|
34
|
+
- **Fast**: Direct SQLite queries, 100-500x faster than bash wrappers
|
|
35
|
+
- **Simple**: Single binary with subcommands
|
|
36
|
+
- **Auto-indexing**: Automatically indexes projects on first query
|
|
37
|
+
- **Token-efficient**: Clean, minimal output optimized for AI consumption
|
|
38
|
+
|
|
39
|
+
## Installation
|
|
40
|
+
|
|
41
|
+
### 1. Install scip-cli
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install scip-cli
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
### 2. Install prerequisites
|
|
48
|
+
|
|
49
|
+
scip-cli requires two external tools for indexing:
|
|
50
|
+
|
|
51
|
+
**For TypeScript/JavaScript projects:**
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
# Install scip-typescript (SCIP indexer)
|
|
55
|
+
npm install -g @sourcegraph/scip-typescript
|
|
56
|
+
|
|
57
|
+
# Install scip (SCIP CLI for index conversion)
|
|
58
|
+
npm install -g @sourcegraph/scip
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
**Verify installation:**
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
scip-cli --help
|
|
65
|
+
scip-typescript --version
|
|
66
|
+
scip --version
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Prerequisites
|
|
70
|
+
|
|
71
|
+
- Python 3.7+
|
|
72
|
+
- `scip-typescript` (for indexing TypeScript/JavaScript)
|
|
73
|
+
- `scip` CLI (for converting indexes)
|
|
74
|
+
|
|
75
|
+
## Usage
|
|
76
|
+
|
|
77
|
+
All commands are subcommands of `scip-cli`:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
scip-cli <command> [arguments]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Commands
|
|
84
|
+
|
|
85
|
+
- `refs <symbol>` - Find all references to a symbol
|
|
86
|
+
- `def <symbol>` - Find symbol definition with source code
|
|
87
|
+
- `search <pattern>` - Search symbols by name pattern
|
|
88
|
+
- `symbols <file>` - List all symbols in a file
|
|
89
|
+
- `rdeps <file>` - Find files that depend on a file
|
|
90
|
+
- `members <symbol>` - List members of a class/interface
|
|
91
|
+
- `skill [path]` - Install or dump the SKILL.md
|
|
92
|
+
|
|
93
|
+
### Examples
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
# Find where useDictation is used
|
|
97
|
+
scip-cli refs useDictation
|
|
98
|
+
|
|
99
|
+
# Get definition of useDictation
|
|
100
|
+
scip-cli def useDictation
|
|
101
|
+
|
|
102
|
+
# Search for symbols matching "Dictation"
|
|
103
|
+
scip-cli search Dictation
|
|
104
|
+
|
|
105
|
+
# List symbols in a file
|
|
106
|
+
scip-cli symbols src/hooks/useDictation.ts
|
|
107
|
+
|
|
108
|
+
# Find files that import from useDictation.ts
|
|
109
|
+
scip-cli rdeps src/hooks/useDictation.ts
|
|
110
|
+
|
|
111
|
+
# List members of a class
|
|
112
|
+
scip-cli members UseDictationOptions
|
|
113
|
+
|
|
114
|
+
# Install skill file
|
|
115
|
+
scip-cli skill ~/.claude/skills/scip/SKILL.md
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
## How It Works
|
|
119
|
+
|
|
120
|
+
1. On first query, automatically indexes the project using `scip-typescript`
|
|
121
|
+
2. Converts the SCIP index to SQLite using `scip expt-convert`
|
|
122
|
+
3. Caches the database in `~/.cache/scip-query/projects/<hash>/index.db`
|
|
123
|
+
4. Subsequent queries are instant SQLite lookups
|
|
124
|
+
|
|
125
|
+
## Performance
|
|
126
|
+
|
|
127
|
+
Compared to bash wrappers:
|
|
128
|
+
- `refs`: 6.4s → 0.03s (213x faster)
|
|
129
|
+
- `def`: 2.8s → 0.05s (56x faster)
|
|
130
|
+
- `search`: 2.6s → 0.03s (87x faster)
|
|
131
|
+
- `symbols`: 0.3s → 0.02s (15x faster)
|
|
132
|
+
- `rdeps`: 0.2s → 0.02s (10x faster)
|
|
133
|
+
- `members`: 3.1s → 0.03s (103x faster)
|
|
134
|
+
|
|
135
|
+
## Architecture
|
|
136
|
+
|
|
137
|
+
```
|
|
138
|
+
scip_cli/
|
|
139
|
+
├── __init__.py
|
|
140
|
+
├── __main__.py # CLI entry point
|
|
141
|
+
├── lib.py # Core utilities (indexing, symbol resolution)
|
|
142
|
+
└── commands/ # Subcommand implementations
|
|
143
|
+
├── refs.py
|
|
144
|
+
├── def_cmd.py
|
|
145
|
+
├── search.py
|
|
146
|
+
├── symbols.py
|
|
147
|
+
├── rdeps.py
|
|
148
|
+
├── members.py
|
|
149
|
+
└── skill.py
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## License
|
|
153
|
+
|
|
154
|
+
MIT
|
scip_cli-1.0.0/README.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# scip-cli
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/py/scip-cli)
|
|
4
|
+
[](https://opensource.org/licenses/MIT)
|
|
5
|
+
|
|
6
|
+
Fast code intelligence CLI for TypeScript/JavaScript projects. Query SCIP indexes directly via SQLite for instant results.
|
|
7
|
+
|
|
8
|
+
## Features
|
|
9
|
+
|
|
10
|
+
- **Fast**: Direct SQLite queries, 100-500x faster than bash wrappers
|
|
11
|
+
- **Simple**: Single binary with subcommands
|
|
12
|
+
- **Auto-indexing**: Automatically indexes projects on first query
|
|
13
|
+
- **Token-efficient**: Clean, minimal output optimized for AI consumption
|
|
14
|
+
|
|
15
|
+
## Installation
|
|
16
|
+
|
|
17
|
+
### 1. Install scip-cli
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pip install scip-cli
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
### 2. Install prerequisites
|
|
24
|
+
|
|
25
|
+
scip-cli requires two external tools for indexing:
|
|
26
|
+
|
|
27
|
+
**For TypeScript/JavaScript projects:**
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
# Install scip-typescript (SCIP indexer)
|
|
31
|
+
npm install -g @sourcegraph/scip-typescript
|
|
32
|
+
|
|
33
|
+
# Install scip (SCIP CLI for index conversion)
|
|
34
|
+
npm install -g @sourcegraph/scip
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
**Verify installation:**
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
scip-cli --help
|
|
41
|
+
scip-typescript --version
|
|
42
|
+
scip --version
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## Prerequisites
|
|
46
|
+
|
|
47
|
+
- Python 3.7+
|
|
48
|
+
- `scip-typescript` (for indexing TypeScript/JavaScript)
|
|
49
|
+
- `scip` CLI (for converting indexes)
|
|
50
|
+
|
|
51
|
+
## Usage
|
|
52
|
+
|
|
53
|
+
All commands are subcommands of `scip-cli`:
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
scip-cli <command> [arguments]
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Commands
|
|
60
|
+
|
|
61
|
+
- `refs <symbol>` - Find all references to a symbol
|
|
62
|
+
- `def <symbol>` - Find symbol definition with source code
|
|
63
|
+
- `search <pattern>` - Search symbols by name pattern
|
|
64
|
+
- `symbols <file>` - List all symbols in a file
|
|
65
|
+
- `rdeps <file>` - Find files that depend on a file
|
|
66
|
+
- `members <symbol>` - List members of a class/interface
|
|
67
|
+
- `skill [path]` - Install or dump the SKILL.md
|
|
68
|
+
|
|
69
|
+
### Examples
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# Find where useDictation is used
|
|
73
|
+
scip-cli refs useDictation
|
|
74
|
+
|
|
75
|
+
# Get definition of useDictation
|
|
76
|
+
scip-cli def useDictation
|
|
77
|
+
|
|
78
|
+
# Search for symbols matching "Dictation"
|
|
79
|
+
scip-cli search Dictation
|
|
80
|
+
|
|
81
|
+
# List symbols in a file
|
|
82
|
+
scip-cli symbols src/hooks/useDictation.ts
|
|
83
|
+
|
|
84
|
+
# Find files that import from useDictation.ts
|
|
85
|
+
scip-cli rdeps src/hooks/useDictation.ts
|
|
86
|
+
|
|
87
|
+
# List members of a class
|
|
88
|
+
scip-cli members UseDictationOptions
|
|
89
|
+
|
|
90
|
+
# Install skill file
|
|
91
|
+
scip-cli skill ~/.claude/skills/scip/SKILL.md
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## How It Works
|
|
95
|
+
|
|
96
|
+
1. On first query, automatically indexes the project using `scip-typescript`
|
|
97
|
+
2. Converts the SCIP index to SQLite using `scip expt-convert`
|
|
98
|
+
3. Caches the database in `~/.cache/scip-query/projects/<hash>/index.db`
|
|
99
|
+
4. Subsequent queries are instant SQLite lookups
|
|
100
|
+
|
|
101
|
+
## Performance
|
|
102
|
+
|
|
103
|
+
Compared to bash wrappers:
|
|
104
|
+
- `refs`: 6.4s → 0.03s (213x faster)
|
|
105
|
+
- `def`: 2.8s → 0.05s (56x faster)
|
|
106
|
+
- `search`: 2.6s → 0.03s (87x faster)
|
|
107
|
+
- `symbols`: 0.3s → 0.02s (15x faster)
|
|
108
|
+
- `rdeps`: 0.2s → 0.02s (10x faster)
|
|
109
|
+
- `members`: 3.1s → 0.03s (103x faster)
|
|
110
|
+
|
|
111
|
+
## Architecture
|
|
112
|
+
|
|
113
|
+
```
|
|
114
|
+
scip_cli/
|
|
115
|
+
├── __init__.py
|
|
116
|
+
├── __main__.py # CLI entry point
|
|
117
|
+
├── lib.py # Core utilities (indexing, symbol resolution)
|
|
118
|
+
└── commands/ # Subcommand implementations
|
|
119
|
+
├── refs.py
|
|
120
|
+
├── def_cmd.py
|
|
121
|
+
├── search.py
|
|
122
|
+
├── symbols.py
|
|
123
|
+
├── rdeps.py
|
|
124
|
+
├── members.py
|
|
125
|
+
└── skill.py
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
## License
|
|
129
|
+
|
|
130
|
+
MIT
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[tool.pytest.ini_options]
|
|
6
|
+
testpaths = ["tests"]
|
|
7
|
+
python_files = ["test_*.py"]
|
|
8
|
+
python_classes = ["Test*"]
|
|
9
|
+
python_functions = ["test_*"]
|
|
10
|
+
addopts = "-v"
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: scip-cli
|
|
3
|
+
description: Read when needing to find symbols, definitions, references, or members in TypeScript/JavaScript code
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
TypeScript/JavaScript only (.ts, .tsx, .js, .jsx) — not GraphQL, CSS, or other files.
|
|
7
|
+
|
|
8
|
+
All commands are sub-commands of `scip-cli`. Run from the project root.
|
|
9
|
+
|
|
10
|
+
## Quick Decision Guide
|
|
11
|
+
|
|
12
|
+
| Question | Use | What you get |
|
|
13
|
+
|----------|-----|--------------|
|
|
14
|
+
| "Where is X defined and what does it do?" | `def X` | Functions: full body. Classes: full definition. Multiple exact matches returned together |
|
|
15
|
+
| "Where is X used/called?" | `refs X` | All file:line locations (~0.03s). Ambiguous bare names → first match only |
|
|
16
|
+
| "What's in this file?" | `symbols file` | All symbols — bare filename works (`HistoryTab`, `usePatientEntries`) |
|
|
17
|
+
| "Find symbols by name" | `search name` | Functions, types, interfaces, classes. Use `--kind variable` for consts |
|
|
18
|
+
| "What files depend on this file?" | `rdeps file` | Importers — bare name works |
|
|
19
|
+
| "What methods does this class have?" | `members ClassName` | All methods/fields with line ranges |
|
|
20
|
+
|
|
21
|
+
## Gotchas
|
|
22
|
+
|
|
23
|
+
- **Bare names** resolve functions, types (aliases + interfaces), and classes. Consts/variables need `def --type variable X` or `search --kind variable X`. Class methods need `members ClassName`, not bare `def methodName`.
|
|
24
|
+
- **Ambiguous types** (e.g. `Opts` in multiple hooks) — `def` returns all; `refs` picks the first and warns. Use `search` or a qualified `src:…` name to disambiguate.
|
|
25
|
+
- **First run** in a project may auto-index (one-time wait, ~10-30s for large codebases).
|
|
26
|
+
- **Precision escape hatch**: qualified names like `src:hooks:usePatientEntries:usePatientEntries()` always work.
|
|
27
|
+
|
|
28
|
+
## Details
|
|
29
|
+
|
|
30
|
+
### def
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
def [--type <kind>] <symbol>
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Kinds: `function`, `class`, `interface`, `type`, `method`, `variable` — use `--type` when the bare name isn't in the default set above.
|
|
37
|
+
|
|
38
|
+
### refs
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
refs <symbol>
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Returns `file:line` for each reference. Reads source files to find exact line numbers.
|
|
45
|
+
|
|
46
|
+
### search
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
search [--kind <kind>] <pattern>
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Returns `file:line Kind symbolName`. Filters noisy symbols (file-level, parameters, type literals).
|
|
53
|
+
|
|
54
|
+
### symbols
|
|
55
|
+
|
|
56
|
+
```bash
|
|
57
|
+
symbols <file>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Returns `startLine-endLine kind name` for each symbol in the file.
|
|
61
|
+
|
|
62
|
+
### rdeps
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
rdeps <file>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Returns list of files that import from this file.
|
|
69
|
+
|
|
70
|
+
### members
|
|
71
|
+
|
|
72
|
+
```bash
|
|
73
|
+
members <symbol>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
Returns `startLine:endLine kind name` for each member. Note: limited by database coverage — `enclosing_symbol` data is sparse for many indexers.
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
"""CLI entry point for scip-cli."""
|
|
3
|
+
import argparse
|
|
4
|
+
import sys
|
|
5
|
+
|
|
6
|
+
from .commands import refs, def_cmd, search, symbols, rdeps, members, skill
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def main():
|
|
10
|
+
parser = argparse.ArgumentParser(
|
|
11
|
+
prog="scip-cli",
|
|
12
|
+
description="Fast code intelligence via SCIP indexes"
|
|
13
|
+
)
|
|
14
|
+
subparsers = parser.add_subparsers(dest="command", help="Available commands")
|
|
15
|
+
|
|
16
|
+
# refs
|
|
17
|
+
refs_parser = subparsers.add_parser("refs", help="Find references to a symbol")
|
|
18
|
+
refs_parser.add_argument("symbol", help="Symbol name")
|
|
19
|
+
|
|
20
|
+
# def
|
|
21
|
+
def_parser = subparsers.add_parser("def", help="Find symbol definition")
|
|
22
|
+
def_parser.add_argument("--type", dest="kind", help="Filter by kind (function, class, etc)")
|
|
23
|
+
def_parser.add_argument("symbol", help="Symbol name")
|
|
24
|
+
|
|
25
|
+
# search
|
|
26
|
+
search_parser = subparsers.add_parser("search", help="Search symbols by pattern")
|
|
27
|
+
search_parser.add_argument("--kind", help="Filter by kind")
|
|
28
|
+
search_parser.add_argument("pattern", help="Search pattern")
|
|
29
|
+
|
|
30
|
+
# symbols
|
|
31
|
+
symbols_parser = subparsers.add_parser("symbols", help="List symbols in a file")
|
|
32
|
+
symbols_parser.add_argument("file", help="File path or pattern")
|
|
33
|
+
|
|
34
|
+
# rdeps
|
|
35
|
+
rdeps_parser = subparsers.add_parser("rdeps", help="Find reverse dependencies of a file")
|
|
36
|
+
rdeps_parser.add_argument("file", help="File path or pattern")
|
|
37
|
+
|
|
38
|
+
# members
|
|
39
|
+
members_parser = subparsers.add_parser("members", help="List members of a class/interface")
|
|
40
|
+
members_parser.add_argument("symbol", help="Symbol name")
|
|
41
|
+
|
|
42
|
+
# skill
|
|
43
|
+
skill_parser = subparsers.add_parser("skill", help="Install or dump the scip-cli SKILL.md")
|
|
44
|
+
skill_parser.add_argument("path", nargs="?", help="Optional file path to write to (creates dirs)")
|
|
45
|
+
|
|
46
|
+
args = parser.parse_args()
|
|
47
|
+
|
|
48
|
+
if not args.command:
|
|
49
|
+
parser.print_help()
|
|
50
|
+
sys.exit(1)
|
|
51
|
+
|
|
52
|
+
# Dispatch to command handlers
|
|
53
|
+
if args.command == "refs":
|
|
54
|
+
refs.main(args)
|
|
55
|
+
elif args.command == "def":
|
|
56
|
+
def_cmd.main(args)
|
|
57
|
+
elif args.command == "search":
|
|
58
|
+
search.main(args)
|
|
59
|
+
elif args.command == "symbols":
|
|
60
|
+
symbols.main(args)
|
|
61
|
+
elif args.command == "rdeps":
|
|
62
|
+
rdeps.main(args)
|
|
63
|
+
elif args.command == "members":
|
|
64
|
+
members.main(args)
|
|
65
|
+
elif args.command == "skill":
|
|
66
|
+
skill.main(args)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
if __name__ == "__main__":
|
|
70
|
+
main()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Command modules for scip-cli."""
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""def command - find symbol definitions."""
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from ..lib import (
|
|
5
|
+
get_db,
|
|
6
|
+
resolve_symbol,
|
|
7
|
+
find_project_root,
|
|
8
|
+
read_source_lines,
|
|
9
|
+
infer_kind,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(args):
|
|
14
|
+
"""Find the definition of a symbol."""
|
|
15
|
+
db = get_db()
|
|
16
|
+
|
|
17
|
+
symbols = resolve_symbol(db, args.symbol, args.kind)
|
|
18
|
+
if not symbols:
|
|
19
|
+
print(f"Symbol '{args.symbol}' not found", file=sys.stderr)
|
|
20
|
+
sys.exit(1)
|
|
21
|
+
|
|
22
|
+
project_root = find_project_root()
|
|
23
|
+
if not project_root:
|
|
24
|
+
print("Error: Could not find project root", file=sys.stderr)
|
|
25
|
+
sys.exit(1)
|
|
26
|
+
|
|
27
|
+
for symbol_id, symbol_str, display_name in symbols:
|
|
28
|
+
# Get definition location from defn_enclosing_ranges
|
|
29
|
+
row = db.execute("""
|
|
30
|
+
SELECT d.relative_path, der.start_line, der.end_line
|
|
31
|
+
FROM defn_enclosing_ranges der
|
|
32
|
+
JOIN documents d ON der.document_id = d.id
|
|
33
|
+
WHERE der.symbol_id = ?
|
|
34
|
+
""", (symbol_id,)).fetchone()
|
|
35
|
+
|
|
36
|
+
if not row:
|
|
37
|
+
continue
|
|
38
|
+
|
|
39
|
+
rel_path, start_line, end_line = row
|
|
40
|
+
kind = infer_kind(symbol_str)
|
|
41
|
+
|
|
42
|
+
# Read source from filesystem
|
|
43
|
+
lines = read_source_lines(project_root, rel_path, start_line, end_line)
|
|
44
|
+
if lines is None:
|
|
45
|
+
source_snippet = "(could not read source)"
|
|
46
|
+
else:
|
|
47
|
+
source_snippet = ''.join(lines).rstrip('\n')
|
|
48
|
+
|
|
49
|
+
print(f"{rel_path}:{start_line + 1}:{end_line + 1}")
|
|
50
|
+
print(source_snippet)
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"""members command - list members of a class/interface."""
|
|
2
|
+
import sys
|
|
3
|
+
import re
|
|
4
|
+
|
|
5
|
+
from ..lib import (
|
|
6
|
+
get_db,
|
|
7
|
+
resolve_symbol,
|
|
8
|
+
warn_ambiguous,
|
|
9
|
+
get_members,
|
|
10
|
+
infer_kind,
|
|
11
|
+
extract_leaf_name,
|
|
12
|
+
read_source_lines,
|
|
13
|
+
find_project_root,
|
|
14
|
+
)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def main(args):
|
|
18
|
+
"""List members of a class or interface."""
|
|
19
|
+
db = get_db()
|
|
20
|
+
|
|
21
|
+
symbols = resolve_symbol(db, args.symbol)
|
|
22
|
+
if not symbols:
|
|
23
|
+
print(f"Symbol '{args.symbol}' not found", file=sys.stderr)
|
|
24
|
+
sys.exit(1)
|
|
25
|
+
|
|
26
|
+
if len(symbols) > 1:
|
|
27
|
+
warn_ambiguous(args.symbol, symbols, "symbol")
|
|
28
|
+
|
|
29
|
+
symbol_id, symbol_str, display_name = symbols[0]
|
|
30
|
+
members = get_members(db, symbol_id)
|
|
31
|
+
|
|
32
|
+
if not members:
|
|
33
|
+
print(f"No members found for '{args.symbol}'", file=sys.stderr)
|
|
34
|
+
sys.exit(1)
|
|
35
|
+
|
|
36
|
+
# Get parent's file path and line range for fallback
|
|
37
|
+
project_root = find_project_root()
|
|
38
|
+
parent_def = db.execute("""
|
|
39
|
+
SELECT d.relative_path, der.start_line, der.end_line
|
|
40
|
+
FROM defn_enclosing_ranges der
|
|
41
|
+
JOIN documents d ON der.document_id = d.id
|
|
42
|
+
WHERE der.symbol_id = ?
|
|
43
|
+
""", (symbol_id,)).fetchone()
|
|
44
|
+
|
|
45
|
+
parent_file = parent_def[0] if parent_def else None
|
|
46
|
+
parent_start = parent_def[1] if parent_def else None
|
|
47
|
+
parent_end = parent_def[2] if parent_def else None
|
|
48
|
+
|
|
49
|
+
# Check if any members need line number lookup
|
|
50
|
+
needs_lookup = any(m[3] is None for m in members)
|
|
51
|
+
|
|
52
|
+
# Read source file once if needed
|
|
53
|
+
source_lines = None
|
|
54
|
+
if needs_lookup and project_root and parent_file and parent_start is not None:
|
|
55
|
+
source_lines = read_source_lines(project_root, parent_file, parent_start, parent_end)
|
|
56
|
+
|
|
57
|
+
for member_id, member_symbol, member_name, start_line, end_line in members:
|
|
58
|
+
kind = infer_kind(member_symbol)
|
|
59
|
+
short = extract_leaf_name(member_symbol)
|
|
60
|
+
|
|
61
|
+
# Skip function parameters (they have ().( in the symbol)
|
|
62
|
+
if ").(" in member_symbol:
|
|
63
|
+
continue
|
|
64
|
+
|
|
65
|
+
# If no line numbers from DB, try to find in source
|
|
66
|
+
if start_line is None and source_lines:
|
|
67
|
+
if "<constructor>" in member_symbol:
|
|
68
|
+
pattern = rf'^\s*constructor\s*\('
|
|
69
|
+
elif "<get>" in member_symbol:
|
|
70
|
+
pattern = rf'^\s*(?:public\s+|private\s+|protected\s+|static\s+|readonly\s+)*get\s+{re.escape(short)}\s*\('
|
|
71
|
+
elif "<set>" in member_symbol:
|
|
72
|
+
pattern = rf'^\s*(?:public\s+|private\s+|protected\s+|static\s+)*set\s+{re.escape(short)}\s*\('
|
|
73
|
+
else:
|
|
74
|
+
# Regular property/method - handle TypeScript modifiers
|
|
75
|
+
pattern = rf'^\s*(?:public\s+|private\s+|protected\s+|static\s+|readonly\s+)*{re.escape(short)}\s*\??\s*[:=(]'
|
|
76
|
+
|
|
77
|
+
for i, line in enumerate(source_lines):
|
|
78
|
+
if re.match(pattern, line):
|
|
79
|
+
start_line = parent_start + i
|
|
80
|
+
end_line = start_line
|
|
81
|
+
break
|
|
82
|
+
|
|
83
|
+
line_info = f"{start_line + 1}:{end_line + 1}" if start_line is not None else "??"
|
|
84
|
+
print(f"{line_info} {kind} {short}")
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
"""rdeps command - find reverse dependencies of a file."""
|
|
2
|
+
import sys
|
|
3
|
+
|
|
4
|
+
from ..lib import (
|
|
5
|
+
get_db,
|
|
6
|
+
resolve_file,
|
|
7
|
+
warn_ambiguous,
|
|
8
|
+
get_file_symbols,
|
|
9
|
+
get_refs_for_symbols,
|
|
10
|
+
)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def main(args):
|
|
14
|
+
"""Find all files that import from this file."""
|
|
15
|
+
db = get_db()
|
|
16
|
+
|
|
17
|
+
# Resolve file pattern to actual path
|
|
18
|
+
files = resolve_file(db, args.file)
|
|
19
|
+
if not files:
|
|
20
|
+
print(f"File '{args.file}' not found", file=sys.stderr)
|
|
21
|
+
sys.exit(1)
|
|
22
|
+
|
|
23
|
+
if len(files) > 1:
|
|
24
|
+
warn_ambiguous(args.file, files, "file")
|
|
25
|
+
|
|
26
|
+
file_path = files[0]
|
|
27
|
+
|
|
28
|
+
# Get all symbols defined in this file
|
|
29
|
+
symbols = get_file_symbols(db, file_path)
|
|
30
|
+
if not symbols:
|
|
31
|
+
print(f"No symbols found in '{file_path}'", file=sys.stderr)
|
|
32
|
+
sys.exit(1)
|
|
33
|
+
|
|
34
|
+
# Get all symbol IDs
|
|
35
|
+
symbol_ids = [s[0] for s in symbols]
|
|
36
|
+
|
|
37
|
+
# Find all references to these symbols from OTHER files in one query
|
|
38
|
+
refs = get_refs_for_symbols(db, symbol_ids)
|
|
39
|
+
|
|
40
|
+
# Collect unique file paths that reference this file
|
|
41
|
+
rdeps = set()
|
|
42
|
+
for symbol_id, ref_list in refs.items():
|
|
43
|
+
for ref_path, ref_line in ref_list:
|
|
44
|
+
if ref_path != file_path:
|
|
45
|
+
rdeps.add(ref_path)
|
|
46
|
+
|
|
47
|
+
if not rdeps:
|
|
48
|
+
print(f"No reverse dependencies found for '{file_path}'", file=sys.stderr)
|
|
49
|
+
sys.exit(1)
|
|
50
|
+
|
|
51
|
+
for dep_path in sorted(rdeps):
|
|
52
|
+
print(dep_path)
|