ucn 3.1.8 → 3.3.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.
@@ -2,76 +2,141 @@
2
2
  name: ucn
3
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
4
  allowed-tools: Bash(ucn *), Bash(npx ucn *)
5
- argument-hint: "[command] [symbol-name]"
5
+ argument-hint: "[command] [symbol-name] [--flags]"
6
6
  ---
7
7
 
8
- # UCN - Semantic Code Navigation
8
+ # UCN - Universal Code Navigator
9
9
 
10
- ## When to Use
10
+ UCN uses tree-sitter ASTs to understand code structure: functions, classes, callers, callees, imports, and dependencies. It works on JavaScript/TypeScript, Python, Go, Rust, and Java.
11
11
 
12
- UCN parses code into ASTs, so it understands structure - not just text patterns.
12
+ ## When to Use vs Skip
13
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)
14
+ **Use UCN when** the codebase is 1000+ LOC and you need:
15
+ - Who calls a function or what it calls
16
+ - What breaks if you change something
17
+ - One function from a large file (without reading the whole file)
18
+ - Unused code detection, dependency graphs
19
19
 
20
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.)
21
+ - Simple text search (TODOs, error messages) use grep
22
+ - Codebase < 500 LOC just read the files
23
+ - Language not supported use grep/read
24
+ - Finding files by name — use glob
24
25
 
25
- ## Commands
26
+ ## Command Format
26
27
 
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
28
+ ```
29
+ ucn [target] <command> [name] [--flags]
35
30
  ```
36
31
 
37
- ### Finding Code
32
+ **Target** (optional, defaults to current directory):
33
+ - Omit or `.` — current project directory (most common)
34
+ - `path/to/file.js` — single file mode
35
+ - `path/to/dir` — specific project directory
36
+ - `"src/**/*.py"` — glob pattern (quote it)
37
+
38
+ **Examples of correct invocation:**
38
39
  ```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
40
+ ucn about handleRequest
41
+ ucn fn parseConfig --file=utils
42
+ ucn toc
43
+ ucn src/api/routes.js fn handleRequest
44
+ ucn impact createUser --exclude=test
44
45
  ```
45
46
 
46
- ### Extracting Code
47
+ ## Commands
48
+
49
+ ### Understand Code
50
+ | Command | Args | What it returns |
51
+ |---------|------|-----------------|
52
+ | `about <name>` | symbol name | Definition + callers + callees + tests + source code. **Start here.** |
53
+ | `context <name>` | symbol name | Callers and callees (numbered — use `expand N` to see code) |
54
+ | `smart <name>` | symbol name | Function source + all helper functions it calls, inline |
55
+ | `impact <name>` | symbol name | Every call site grouped by file. Use before modifying a function. |
56
+ | `trace <name>` | symbol name | Call tree (who calls who) at `--depth=N` (default 3) |
57
+ | `example <name>` | symbol name | Best real usage example with surrounding context |
58
+
59
+ ### Find Code
60
+ | Command | Args | What it returns |
61
+ |---------|------|-----------------|
62
+ | `find <name>` | symbol name | Definitions ranked by usage count (top 5) |
63
+ | `usages <name>` | symbol name | All usages grouped: definitions, calls, imports, references |
64
+ | `toc` | none | Table of contents: all functions, classes, exports |
65
+ | `tests <name>` | symbol name | Test files and test functions for the given symbol |
66
+ | `search <text>` | search term | Text search (grep-like, but respects project ignores) |
67
+ | `deadcode` | none | Lists all functions/classes with zero callers |
68
+
69
+ ### Extract Code
70
+ | Command | Args | What it returns |
71
+ |---------|------|-----------------|
72
+ | `fn <name>` | function name | Full function source code |
73
+ | `class <name>` | class name | Full class source code |
74
+ | `lines <range>` | e.g. `50-100` | Lines from file. In project mode requires `--file=<path>` |
75
+ | `expand <N>` | number | Source code for numbered item from last `context` output |
76
+
77
+ ### Dependencies
78
+ | Command | Args | What it returns |
79
+ |---------|------|-----------------|
80
+ | `imports <file>` | relative path | What the file imports (modules, symbols) |
81
+ | `exporters <file>` | relative path | Which files import this file |
82
+ | `file-exports <file>` | relative path | What the file exports |
83
+ | `graph <file>` | relative path | Dependency tree at `--depth=N` |
84
+
85
+ ### Refactoring
86
+ | Command | Args | What it returns |
87
+ |---------|------|-----------------|
88
+ | `verify <name>` | function name | Checks all call sites match the function's signature |
89
+ | `plan <name>` | function name | Preview refactoring with `--rename-to`, `--add-param`, `--remove-param` |
90
+ | `related <name>` | symbol name | Functions in same file or sharing dependencies |
91
+
92
+ ## Key Flags
93
+
94
+ | Flag | Works with | Effect |
95
+ |------|-----------|--------|
96
+ | `--file=<pattern>` | any symbol command | Filter by file path when name is ambiguous (e.g., `--file=routes`) |
97
+ | `--exclude=a,b` | any | Exclude files matching patterns (e.g., `--exclude=test,mock`) |
98
+ | `--in=<path>` | any | Only search within path (e.g., `--in=src/core`) |
99
+ | `--include-tests` | any | Include test files in results (excluded by default) |
100
+ | `--include-methods` | `context`, `smart` | Include `obj.method()` calls (only direct calls shown by default) |
101
+ | `--depth=N` | `trace`, `graph`, `about`, `find` | Tree/expansion depth (default 3) |
102
+ | `--context=N` | `usages`, `search` | Lines of context around each match |
103
+ | `--json` | any | Machine-readable JSON output |
104
+ | `--code-only` | `search` | Exclude matches in comments and strings |
105
+ | `--with-types` | `smart`, `about` | Include type definitions |
106
+ | `--top=N` / `--all` | `find`, `usages` | Limit results to top N, or show all |
107
+ | `--no-cache` | any | Skip cached index (use after file changes) |
108
+ | `--clear-cache` | any | Delete cached index before running |
109
+
110
+ ## Common Patterns
111
+
112
+ **Investigate a function (first stop):**
47
113
  ```bash
48
- ucn fn <name> # Extract function
49
- ucn fn <name> --file routes # Disambiguate by path
50
- ucn class <name> # Extract class
114
+ ucn about handleRequest
51
115
  ```
52
116
 
53
- ### Dependencies
117
+ **Before modifying a function:**
54
118
  ```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
119
+ ucn impact handleRequest # See all callers
120
+ ucn smart handleRequest # See function + its helpers
59
121
  ```
60
122
 
61
- ## Flags
123
+ **Extract one function from a large file:**
124
+ ```bash
125
+ ucn fn handleRequest --file=api # Disambiguate by file path
126
+ ```
62
127
 
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
128
+ **Find unused code:**
129
+ ```bash
130
+ ucn deadcode
131
+ ```
72
132
 
73
- ## More Info
133
+ **Understand a file's role:**
134
+ ```bash
135
+ ucn imports core/project.js # What it depends on
136
+ ucn exporters core/project.js # Who depends on it
137
+ ```
74
138
 
139
+ **Multiple queries (keeps index in memory):**
75
140
  ```bash
76
- ucn --help # Full command reference
141
+ ucn --interactive
77
142
  ```
package/README.md CHANGED
@@ -1,38 +1,140 @@
1
1
  # UCN - Universal Code Navigator
2
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.
3
+ AI agents working with large codebases often read entire files just to understand a single function. UCN uses tree-sitter ASTs to extract exactly what you need functions, callers, callees, dependencies without wasting context.
4
4
 
5
- ## Example
5
+ ## Examples
6
6
 
7
- A 2000-line file and need to understand `handleRequest`:
7
+ **Extract a function** from a large file without reading it:
8
+ ```
9
+ $ ucn fn expandGlob
10
+ core/discovery.js:135
11
+ [ 135- 166] expandGlob(pattern, options = {})
12
+ ────────────────────────────────────────────────────────────
13
+ function expandGlob(pattern, options = {}) {
14
+ const root = path.resolve(options.root || process.cwd());
15
+ const ignores = options.ignores || DEFAULT_IGNORES;
16
+ ...
17
+ return files.sort(compareNames);
18
+ }
19
+ ```
8
20
 
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);
21
+ **See who calls a function and what it calls:**
22
+ ```
23
+ $ ucn context expandGlob
24
+ Context for expandGlob:
25
+ ════════════════════════════════════════════════════════════
26
+
27
+ CALLERS (7):
28
+ [1] cli/index.js:1847 [runGlobCommand]
29
+ const files = expandGlob(pattern);
30
+ [2] core/project.js:81
31
+ const files = expandGlob(pattern, {
32
+ [3] core/project.js:3434
33
+ const currentFiles = expandGlob(pattern, { root: this.root });
34
+ ...
35
+
36
+ CALLEES (2):
37
+ [8] parseGlobPattern [utility] - core/discovery.js:171
38
+ [9] walkDir [utility] - core/discovery.js:227
39
+ ```
40
+
41
+ **See what breaks if you change a function:**
42
+ ```
43
+ $ ucn impact shouldIgnore
44
+ Impact analysis for shouldIgnore
45
+ ════════════════════════════════════════════════════════════
46
+ core/discovery.js:289
47
+ shouldIgnore (name, ignores, parentDir)
48
+
49
+ CALL SITES: 2
50
+ Files affected: 1
51
+
52
+ BY FILE:
53
+
54
+ core/discovery.js (2 calls)
55
+ :255 [walkDir]
56
+ if (shouldIgnore(entry.name, options.ignores, dir)) continue;
57
+ args: entry.name, options.ignores, dir
58
+ :373 [detectProjectPattern]
59
+ !shouldIgnore(entry.name, DEFAULT_IGNORES)) {
60
+ args: entry.name, DEFAULT_IGNORES
61
+ ```
62
+
63
+ **Get a function with all its dependencies inline:**
64
+ ```
65
+ $ ucn smart shouldIgnore
66
+ shouldIgnore (/Users/mihail/ucn/core/discovery.js:289)
67
+ ════════════════════════════════════════════════════════════
68
+ function shouldIgnore(name, ignores, parentDir) {
69
+ for (const pattern of ignores) {
70
+ if (pattern.includes('*')) {
71
+ const regex = globToRegex(pattern);
72
+ ...
73
+ }
74
+ }
75
+ ...
18
76
  }
19
77
 
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]
78
+ ─── DEPENDENCIES ───
25
79
 
26
- CALLEES (3):
27
- validateInput - src/utils/validation.js:12
28
- processData - src/services/data.js:89
29
- sendResponse - src/utils/response.js:34
80
+ // globToRegex [utility] (core/discovery.js:208)
81
+ function globToRegex(glob) {
82
+ let regex = glob.replace(/[.+^$[\]\\]/g, '\\$&');
83
+ ...
84
+ return new RegExp('^' + regex + '$');
85
+ }
30
86
  ```
31
87
 
32
- 18 lines of context instead of 2000.
88
+ **Trace the call tree:**
89
+ ```
90
+ $ ucn trace expandGlob --depth=2
91
+ Call tree for expandGlob
92
+ ════════════════════════════════════════════════════════════
93
+
94
+ expandGlob
95
+ ├── parseGlobPattern (core/discovery.js:171) [utility] 1x
96
+ │ └── globToRegex (core/discovery.js:208) [utility] 1x
97
+ └── walkDir (core/discovery.js:227) [utility] 1x
98
+ └── shouldIgnore (core/discovery.js:289) [utility] 1x
99
+ ```
100
+
101
+ **Find unused code:**
102
+ ```
103
+ $ ucn deadcode
104
+ Dead code: 15 unused symbol(s)
105
+
106
+ cli/index.js
107
+ [1649-1654] extractFunctionNameFromContent (function)
108
+ core/project.js
109
+ [1664-1694] findReExportsOf (method)
110
+ [1998-2020] withCompleteness (method)
111
+ ...
112
+ ```
113
+
114
+ **See a file's dependencies:**
115
+ ```
116
+ $ ucn imports core/project.js
117
+ Imports in core/project.js:
118
+
119
+ INTERNAL:
120
+ ./discovery
121
+ -> core/discovery.js
122
+ expandGlob, findProjectRoot, detectProjectPattern, isTestFile
123
+ ./imports
124
+ -> core/imports.js
125
+ extractImports, extractExports, resolveImport
126
+ ./parser
127
+ -> core/parser.js
128
+ parseFile
129
+ ../languages
130
+ -> languages/index.js
131
+ detectLanguage, getParser, getLanguageModule, PARSE_OPTIONS, safeParse
132
+
133
+ EXTERNAL:
134
+ fs, path, crypto
135
+ ```
33
136
 
34
137
  ## Supported Languages
35
- The supported languages can grow as tree-sitter supports many, but for my use cases I've added support for:
36
138
 
37
139
  JavaScript, TypeScript, Python, Go, Rust, Java
38
140
 
@@ -75,49 +177,65 @@ cp -r ucn/.claude/skills/ucn ~/.agents/skills/
75
177
  ## Usage
76
178
 
77
179
  ```
180
+ UCN - Universal Code Navigator
181
+
182
+ Supported: JavaScript, TypeScript, Python, Go, Rust, Java
183
+
78
184
  Usage:
79
185
  ucn [command] [args] Project mode (current directory)
80
186
  ucn <file> [command] [args] Single file mode
81
187
  ucn <dir> [command] [args] Project mode (specific directory)
82
188
  ucn "pattern" [command] [args] Glob pattern mode
83
189
 
84
- UNDERSTAND CODE
85
- about <name> Full picture (definition, callers, callees, tests, code)
86
- context <name> Who calls this + what it calls
190
+ ═══════════════════════════════════════════════════════════════════════════════
191
+ UNDERSTAND CODE (UCN's strength - semantic analysis)
192
+ ═══════════════════════════════════════════════════════════════════════════════
193
+ about <name> RECOMMENDED: Full picture (definition, callers, callees, tests, code)
194
+ context <name> Who calls this + what it calls (numbered for expand)
87
195
  smart <name> Function + all dependencies inline
88
196
  impact <name> What breaks if changed (call sites grouped by file)
89
197
  trace <name> Call tree visualization (--depth=N)
90
198
 
199
+ ═══════════════════════════════════════════════════════════════════════════════
91
200
  FIND CODE
201
+ ═══════════════════════════════════════════════════════════════════════════════
92
202
  find <name> Find symbol definitions (top 5 by usage count)
93
203
  usages <name> All usages grouped: definitions, calls, imports, references
94
- toc Table of contents (functions, classes, state)
95
- search <term> Text search
204
+ toc Table of contents (compact; --detailed lists all symbols)
205
+ search <term> Text search (for simple patterns, consider grep instead)
96
206
  tests <name> Find test files for a function
97
207
 
208
+ ═══════════════════════════════════════════════════════════════════════════════
98
209
  EXTRACT CODE
210
+ ═══════════════════════════════════════════════════════════════════════════════
99
211
  fn <name> Extract function (--file to disambiguate)
100
212
  class <name> Extract class
101
213
  lines <range> Extract line range (e.g., lines 50-100)
102
214
  expand <N> Show code for item N from context output
103
215
 
216
+ ═══════════════════════════════════════════════════════════════════════════════
104
217
  FILE DEPENDENCIES
218
+ ═══════════════════════════════════════════════════════════════════════════════
105
219
  imports <file> What does file import
106
220
  exporters <file> Who imports this file
107
221
  file-exports <file> What does file export
108
222
  graph <file> Full dependency tree (--depth=N)
109
223
 
224
+ ═══════════════════════════════════════════════════════════════════════════════
110
225
  REFACTORING HELPERS
226
+ ═══════════════════════════════════════════════════════════════════════════════
111
227
  plan <name> Preview refactoring (--add-param, --remove-param, --rename-to)
112
228
  verify <name> Check all call sites match signature
113
229
  deadcode Find unused functions/classes
114
230
  related <name> Find similar functions (same file, shared deps)
115
231
 
232
+ ═══════════════════════════════════════════════════════════════════════════════
116
233
  OTHER
234
+ ═══════════════════════════════════════════════════════════════════════════════
117
235
  api Show exported/public symbols
118
236
  typedef <name> Find type definitions
119
237
  stats Project statistics
120
- stacktrace <text> Parse stack trace, show code at each frame
238
+ stacktrace <text> Parse stack trace, show code at each frame (alias: stack)
121
239
  example <name> Best usage example with context
122
240
 
123
241
  Common Flags:
@@ -132,9 +250,21 @@ Common Flags:
132
250
  --top=N / --all Limit or show all results
133
251
  --include-tests Include test files
134
252
  --include-methods Include method calls (obj.fn) in caller/callee analysis
253
+ --include-uncertain Include ambiguous/uncertain call matches
254
+ --include-exported Include exported symbols in deadcode
255
+ --detailed List all symbols in toc (compact counts by default)
135
256
  --no-cache Disable caching
136
257
  --clear-cache Clear cache before running
258
+ --no-follow-symlinks Don't follow symbolic links
137
259
  -i, --interactive Keep index in memory for multiple queries
260
+
261
+ Quick Start:
262
+ ucn toc # See project structure (compact)
263
+ ucn toc --detailed # List all functions/classes
264
+ ucn about handleRequest # Understand a function
265
+ ucn impact handleRequest # Before modifying
266
+ ucn fn handleRequest --file api # Extract specific function
267
+ ucn --interactive # Multiple queries
138
268
  ```
139
269
 
140
270
  ## License