ucn 3.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/.claude/skills/ucn/SKILL.md +77 -0
- package/LICENSE +21 -0
- package/README.md +135 -0
- package/cli/index.js +2437 -0
- package/core/discovery.js +513 -0
- package/core/imports.js +558 -0
- package/core/output.js +1274 -0
- package/core/parser.js +279 -0
- package/core/project.js +3261 -0
- package/index.js +52 -0
- package/languages/go.js +653 -0
- package/languages/index.js +267 -0
- package/languages/java.js +826 -0
- package/languages/javascript.js +1346 -0
- package/languages/python.js +667 -0
- package/languages/rust.js +950 -0
- package/languages/utils.js +457 -0
- package/package.json +42 -0
- package/test/fixtures/go/go.mod +3 -0
- package/test/fixtures/go/main.go +257 -0
- package/test/fixtures/go/service.go +187 -0
- package/test/fixtures/java/DataService.java +279 -0
- package/test/fixtures/java/Main.java +287 -0
- package/test/fixtures/java/Utils.java +199 -0
- package/test/fixtures/java/pom.xml +6 -0
- package/test/fixtures/javascript/main.js +109 -0
- package/test/fixtures/javascript/package.json +1 -0
- package/test/fixtures/javascript/service.js +88 -0
- package/test/fixtures/javascript/utils.js +67 -0
- package/test/fixtures/python/main.py +198 -0
- package/test/fixtures/python/pyproject.toml +3 -0
- package/test/fixtures/python/service.py +166 -0
- package/test/fixtures/python/utils.py +118 -0
- package/test/fixtures/rust/Cargo.toml +3 -0
- package/test/fixtures/rust/main.rs +253 -0
- package/test/fixtures/rust/service.rs +210 -0
- package/test/fixtures/rust/utils.rs +154 -0
- package/test/fixtures/typescript/main.ts +154 -0
- package/test/fixtures/typescript/package.json +1 -0
- package/test/fixtures/typescript/repository.ts +149 -0
- package/test/fixtures/typescript/types.ts +114 -0
- package/test/parser.test.js +3661 -0
- package/test/public-repos-test.js +477 -0
- package/test/systematic-test.js +619 -0
- package/ucn.js +8 -0
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ucn
|
|
3
|
+
description: Universal Code Navigator - extracts specific functions and their relationships (callers, callees, dependencies) without reading entire files. Use when you need one function from a large file or need to understand what calls/is called by a function. Saves context in codebases 1000+ LOC. Skip for simple text search, tiny codebases, or unsupported languages (only JS/TS, Python, Go, Rust, Java).
|
|
4
|
+
allowed-tools: Bash(ucn *), Bash(npx ucn *)
|
|
5
|
+
argument-hint: "[command] [symbol-name]"
|
|
6
|
+
---
|
|
7
|
+
|
|
8
|
+
# UCN - Semantic Code Navigation
|
|
9
|
+
|
|
10
|
+
## When to Use
|
|
11
|
+
|
|
12
|
+
UCN parses code into ASTs, so it understands structure - not just text patterns.
|
|
13
|
+
|
|
14
|
+
**Use UCN when:**
|
|
15
|
+
- You need to understand relationships (callers, callees, dependencies)
|
|
16
|
+
- You're about to modify code and need to know the impact
|
|
17
|
+
- You want to extract a specific function without reading the whole file
|
|
18
|
+
- Codebase is 1000+ LOC (indexing overhead pays off)
|
|
19
|
+
|
|
20
|
+
**Skip UCN when:**
|
|
21
|
+
- Simple text search (error messages, TODOs, literals)
|
|
22
|
+
- Codebase is tiny (< 500 LOC) - just read the files
|
|
23
|
+
- Language not supported (C, Ruby, PHP, etc.)
|
|
24
|
+
|
|
25
|
+
## Commands
|
|
26
|
+
|
|
27
|
+
### Understanding Code
|
|
28
|
+
```bash
|
|
29
|
+
ucn about <name> # Definition, callers, callees, tests, code
|
|
30
|
+
ucn context <name> # Callers + callees
|
|
31
|
+
ucn smart <name> # Function + dependencies inline
|
|
32
|
+
ucn impact <name> # All call sites by file
|
|
33
|
+
ucn trace <name> # Call tree
|
|
34
|
+
ucn example <name> # Best usage example with context
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Finding Code
|
|
38
|
+
```bash
|
|
39
|
+
ucn find <name> # Find definitions
|
|
40
|
+
ucn usages <name> # All usages by type
|
|
41
|
+
ucn toc # Table of contents
|
|
42
|
+
ucn tests <name> # Find tests for a function
|
|
43
|
+
ucn deadcode # Find unused functions/classes
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### Extracting Code
|
|
47
|
+
```bash
|
|
48
|
+
ucn fn <name> # Extract function
|
|
49
|
+
ucn fn <name> --file routes # Disambiguate by path
|
|
50
|
+
ucn class <name> # Extract class
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Dependencies
|
|
54
|
+
```bash
|
|
55
|
+
ucn imports <file> # What this file imports
|
|
56
|
+
ucn exporters <file> # Who imports this file
|
|
57
|
+
ucn file-exports <file> # What this file exports
|
|
58
|
+
ucn graph <file> # Dependency tree
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Flags
|
|
62
|
+
|
|
63
|
+
- `--file <pattern>` - Filter by file path
|
|
64
|
+
- `--exclude=test,mock` - Exclude files
|
|
65
|
+
- `--depth=N` - Tree depth
|
|
66
|
+
- `--context=N` - Lines of context around matches
|
|
67
|
+
- `--code-only` - Filter out comments and strings
|
|
68
|
+
- `--include-methods` - Include obj.method() calls
|
|
69
|
+
- `--include-tests` - Include test files
|
|
70
|
+
- `--no-cache` - Disable caching
|
|
71
|
+
- `--clear-cache` - Clear cache before running
|
|
72
|
+
|
|
73
|
+
## More Info
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
ucn --help # Full command reference
|
|
77
|
+
```
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Mihail
|
|
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,135 @@
|
|
|
1
|
+
# UCN - Universal Code Navigator
|
|
2
|
+
|
|
3
|
+
When working with large codebases or even vibe coding all into a single large file, AI agents often need to read entire files just to understand a single function. This eats up the context rather fast, so the intent is to keep the agents perform better with their context clean than rather cluttered.
|
|
4
|
+
|
|
5
|
+
## Example
|
|
6
|
+
|
|
7
|
+
A 2000-line file and need to understand `handleRequest`:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
$ ucn fn handleRequest
|
|
11
|
+
src/api/routes.js:145
|
|
12
|
+
[145-162] handleRequest(req, res)
|
|
13
|
+
────────────────────────────────────────────────────────
|
|
14
|
+
function handleRequest(req, res) {
|
|
15
|
+
const validated = validateInput(req.body);
|
|
16
|
+
const result = processData(validated);
|
|
17
|
+
return sendResponse(res, result);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
$ ucn context handleRequest
|
|
21
|
+
CALLERS (3):
|
|
22
|
+
src/server.js:45 [startServer]
|
|
23
|
+
src/middleware.js:23 [authMiddleware]
|
|
24
|
+
test/api.test.js:67 [testHandler]
|
|
25
|
+
|
|
26
|
+
CALLEES (3):
|
|
27
|
+
validateInput - src/utils/validation.js:12
|
|
28
|
+
processData - src/services/data.js:89
|
|
29
|
+
sendResponse - src/utils/response.js:34
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
18 lines of context instead of 2000.
|
|
33
|
+
|
|
34
|
+
## Supported Languages
|
|
35
|
+
The supported languages can grow as tree-sitter supports many, but for my use cases I've added support for:
|
|
36
|
+
|
|
37
|
+
JavaScript, TypeScript, Python, Go, Rust, Java
|
|
38
|
+
|
|
39
|
+
## Install
|
|
40
|
+
|
|
41
|
+
Not published to npm yet. Install from source:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
git clone https://github.com/mleoca/ucn.git
|
|
45
|
+
cd ucn
|
|
46
|
+
npm install
|
|
47
|
+
npm link # makes 'ucn' available globally
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### Claude Code (optional)
|
|
51
|
+
|
|
52
|
+
To use UCN as a skill in Claude Code:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
mkdir -p ~/.claude/skills
|
|
56
|
+
cp -r ucn/.claude/skills/ucn ~/.claude/skills/
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
### Codex (optional)
|
|
60
|
+
|
|
61
|
+
To use UCN as a skill in OpenAI Codex:
|
|
62
|
+
|
|
63
|
+
```bash
|
|
64
|
+
mkdir -p ~/.agents/skills
|
|
65
|
+
cp -r ucn/.claude/skills/ucn ~/.agents/skills/
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## Usage
|
|
69
|
+
|
|
70
|
+
```
|
|
71
|
+
Usage:
|
|
72
|
+
ucn [command] [args] Project mode (current directory)
|
|
73
|
+
ucn <file> [command] [args] Single file mode
|
|
74
|
+
ucn <dir> [command] [args] Project mode (specific directory)
|
|
75
|
+
ucn "pattern" [command] [args] Glob pattern mode
|
|
76
|
+
|
|
77
|
+
UNDERSTAND CODE
|
|
78
|
+
about <name> Full picture (definition, callers, callees, tests, code)
|
|
79
|
+
context <name> Who calls this + what it calls
|
|
80
|
+
smart <name> Function + all dependencies inline
|
|
81
|
+
impact <name> What breaks if changed (call sites grouped by file)
|
|
82
|
+
trace <name> Call tree visualization (--depth=N)
|
|
83
|
+
|
|
84
|
+
FIND CODE
|
|
85
|
+
find <name> Find symbol definitions (top 5 by usage count)
|
|
86
|
+
usages <name> All usages grouped: definitions, calls, imports, references
|
|
87
|
+
toc Table of contents (functions, classes, state)
|
|
88
|
+
search <term> Text search
|
|
89
|
+
tests <name> Find test files for a function
|
|
90
|
+
|
|
91
|
+
EXTRACT CODE
|
|
92
|
+
fn <name> Extract function (--file to disambiguate)
|
|
93
|
+
class <name> Extract class
|
|
94
|
+
lines <range> Extract line range (e.g., lines 50-100)
|
|
95
|
+
expand <N> Show code for item N from context output
|
|
96
|
+
|
|
97
|
+
FILE DEPENDENCIES
|
|
98
|
+
imports <file> What does file import
|
|
99
|
+
exporters <file> Who imports this file
|
|
100
|
+
file-exports <file> What does file export
|
|
101
|
+
graph <file> Full dependency tree (--depth=N)
|
|
102
|
+
|
|
103
|
+
REFACTORING HELPERS
|
|
104
|
+
plan <name> Preview refactoring (--add-param, --remove-param, --rename-to)
|
|
105
|
+
verify <name> Check all call sites match signature
|
|
106
|
+
deadcode Find unused functions/classes
|
|
107
|
+
related <name> Find similar functions (same file, shared deps)
|
|
108
|
+
|
|
109
|
+
OTHER
|
|
110
|
+
api Show exported/public symbols
|
|
111
|
+
typedef <name> Find type definitions
|
|
112
|
+
stats Project statistics
|
|
113
|
+
stacktrace <text> Parse stack trace, show code at each frame
|
|
114
|
+
example <name> Best usage example with context
|
|
115
|
+
|
|
116
|
+
Common Flags:
|
|
117
|
+
--file <pattern> Filter by file path (e.g., --file=routes)
|
|
118
|
+
--exclude=a,b Exclude patterns (e.g., --exclude=test,mock)
|
|
119
|
+
--in=<path> Only in path (e.g., --in=src/core)
|
|
120
|
+
--depth=N Trace/graph depth (default: 3)
|
|
121
|
+
--context=N Lines of context around matches
|
|
122
|
+
--json Machine-readable output
|
|
123
|
+
--code-only Filter out comments and strings
|
|
124
|
+
--with-types Include type definitions
|
|
125
|
+
--top=N / --all Limit or show all results
|
|
126
|
+
--include-tests Include test files
|
|
127
|
+
--include-methods Include method calls (obj.fn) in caller/callee analysis
|
|
128
|
+
--no-cache Disable caching
|
|
129
|
+
--clear-cache Clear cache before running
|
|
130
|
+
-i, --interactive Keep index in memory for multiple queries
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
MIT
|