ucn 4.1.3 → 4.2.2

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.
@@ -1,388 +1,115 @@
1
1
  ---
2
2
  name: ucn
3
- description: "Code intelligence toolkit extract functions, trace callers, analyze impact, detect dead code without reading whole files. PREFER over grep+read when you need: who calls a function, what breaks if you change it, or the full call chain of a pipeline. `ucn orient` gives a one-screen overview of any new repo. One `ucn about` replaces 3-4 grep+read cycles. One `ucn trace` maps an entire execution flow without reading any files. Works on JS/TS, Python, Go, Rust, Java, HTML. Skip for plain text search or codebases under 500 LOC."
4
- allowed-tools: Bash(ucn *), Bash(npx ucn *)
5
- argument-hint: "[command] [symbol-name] [--flags]"
3
+ description: AST code intelligence for JavaScript/TypeScript, Python, Go, Rust, Java, and HTML. Use in repositories over roughly 500 LOC to orient, extract symbols, trace callers or callees, assess impact, verify call sites, select tests, or investigate dead code. Prefer it over repeated grep-and-read cycles for semantic questions; use text search for literals, messages, configuration, and unsupported languages.
6
4
  ---
7
5
 
8
- # UCN — Universal Code Navigator
6
+ # UCN
9
7
 
10
- Extract functions, trace call chains, find callers, and detect dead code without reading entire files. Works on JS/TS, Python, Go, Rust, Java, and HTML (inline scripts and event handlers).
8
+ Use UCN to gather compact, auditable code evidence before reading large files or changing a symbol.
11
9
 
12
- ## When to Reach for UCN Instead of Grep/Read
10
+ ## Start here
13
11
 
14
- **Use UCN when the next action would be:**
12
+ 1. Run `ucn orient` in an unfamiliar repository.
13
+ 2. Pin the symbol. Use `ucn find <name>` when a name is ambiguous, then pass the emitted `path:line:name` handle to later commands.
14
+ 3. Run `ucn about <handle> --compact` for definition, direct callers, callees, tests, and contract metadata.
15
+ 4. Before a change, run `ucn impact <handle>` and `ucn affected-tests <handle>`.
16
+ 5. After a signature change, run `ucn verify <handle>`. Before committing, run `ucn check`.
17
+ 6. Read source with `ucn fn`, `ucn class`, or `ucn lines` only when the evidence indicates that source inspection is needed.
15
18
 
16
- - "I just opened this repo, where do I start?" `ucn orient` one screen: size, top dirs, hot functions, entry points, trust verdict
17
- - "Let me grep for all callers of this function" → `ucn impact <name>` — finds every call site, grouped by file, with args shown
18
- - "Let me read this 800-line file to find one function" → `ucn fn <name> --file=<hint>` — extracts just that function
19
- - "Let me trace through this code to understand the flow" → `ucn trace <name> --depth=3` — shows the full call tree without reading any files
20
- - "I need to understand this function before changing it" → `ucn about <name>` — returns definition + callers + callees + tests + source in one call
21
- - "I wonder if anything still uses this code" → `ucn deadcode` — lists every function/class with zero callers
19
+ Prefer `--json` when another tool or script will consume the answer. MCP `about`, `context`, and `impact` default to compact output; request `compact=false` only when source and previews are necessary.
22
20
 
23
- **Stick with grep/read when:**
21
+ ## CLI, MCP, and skill behavior
24
22
 
25
- - Searching for a string literal, error message, TODO, or config value
26
- - The codebase is under 500 LOC — just read the files
27
- - Language not supported (only JS/TS, Python, Go, Rust, Java, HTML)
28
- - Finding files by name — use glob
23
+ The skill is guidance, not a separate analysis engine. It tells the agent when and how to call UCN through the CLI or MCP.
29
24
 
30
- ## The Commands You'll Use Most
25
+ CLI and MCP resolve commands through the same registry, execute the same handlers, use the same project index and persisted cache, and call the same output formatters. Their defaults differ by transport:
31
26
 
32
- ### 1. `about` First stop for any investigation
27
+ - CLI uses full text by default and emits raw JSON with `--json`.
28
+ - MCP defaults `about`, `context`, and `impact` to compact text. It uses a 10K character default for targeted commands, 3K for broad commands, and a 100K hard ceiling. Contract metadata is preserved when output is truncated.
29
+ - MCP uses snake_case command and parameter names. CLI uses hyphenated command and flag names.
30
+ - To compare text, align compact/full settings and result caps. Surface-specific retry hints may still use CLI or MCP spelling.
33
31
 
34
- One command returns: definition, source code, who calls it, what it calls, related tests.
32
+ MCP keeps the process and project index warm across calls, so repeated MCP queries usually avoid CLI process startup. The semantic work and cache format are otherwise shared.
35
33
 
36
- ```bash
37
- ucn about compute_composite
38
- ```
34
+ ## Read every answer as evidence, not proof
39
35
 
40
- Replaces: grep for definition read the file → grep for callers → grep for tests. All in one call.
36
+ For `about`, `context`, and `impact`, interpret caller results in two bands:
41
37
 
42
- ### 2. `impact` Before changing any function
38
+ - `CONFIRMED`: the call site has binding, receiver, import, or ownership evidence for the pinned target.
39
+ - `UNVERIFIED`: the syntax could call the target, but the engine cannot prove the identity. Review these sites before a breaking change.
43
40
 
44
- Shows every call site with arguments and surrounding context, without truncation. Essential before modifying a signature, renaming, or deleting.
41
+ Then inspect all contract signals:
45
42
 
46
- ```bash
47
- ucn impact score_trend # Every caller, grouped by file
48
- ucn impact score_trend --exclude=test # Only production callers
49
- ```
43
+ - `ACCOUNT` partitions literal-name text occurrences into confirmed, unverified, non-call, excluded, and unresolved buckets. It is an arithmetic conservation check, not a semantic-completeness claim.
44
+ - `CONTRACT` states whether that literal-name partition is complete. `observed-text zero` means no caller was found in that observed text set. It does not prove semantic zero and is never safe-delete proof.
45
+ - `WARNING` means parsing, reading, or indexing was incomplete. Inspect the named files with text search or the compiler.
46
+ - `FILTERED` means flags hid evidence from display. Remove the filters before a breaking change.
47
+ - `beyond-text callers` are alias- or binding-resolved edges that a literal grep would miss.
48
+ - Numeric evidence scores are ordinal ranking weights, not calibrated probabilities or accuracy percentages.
49
+ - Truncated MCP output preserves contract metadata when possible. If `contractMetadataComplete` is false, rerun with a larger output budget or narrower scope.
50
50
 
51
- Replaces: grep for the function name manually filtering definitions vs calls vs imports reading context around each match.
51
+ Do not claim “no callers,” “safe to delete,” or “safe to refactor” from a zero result alone.
52
52
 
53
- ### 3. `blast` Transitive blast radius
53
+ ## Match the command to the decision
54
54
 
55
- Walks UP the caller chain recursively. Shows the full tree of functions affected transitively if you change something. Like `impact` but recursive — answers "what breaks if I change this, including indirect callers?"
55
+ | Decision | Command |
56
+ |---|---|
57
+ | Understand one symbol | `ucn about <handle> --compact` |
58
+ | Direct change impact | `ucn impact <handle>` |
59
+ | Transitive callers | `ucn blast <handle> --depth=3` |
60
+ | Downward execution flow | `ucn trace <handle> --depth=3` |
61
+ | Paths from entry points | `ucn reverse-trace <handle>` |
62
+ | Tests affected by a change | `ucn affected-tests <handle>` |
63
+ | Validate call-site arity | `ucn verify <handle>` |
64
+ | Pre-commit review | `ucn check [--base=main]` |
65
+ | Exact source extraction | `ucn fn <handle>` or `ucn class <handle>` |
66
+ | All references, not only calls | `ucn usages <name>` |
67
+ | Potentially unreachable code | `ucn deadcode` |
68
+ | Index limitations and readiness | `ucn doctor --deep` |
56
69
 
57
- ```bash
58
- ucn blast helper # callers of callers (depth 3)
59
- ucn blast helper --depth=5 # deeper chain
60
- ucn blast helper --exclude=test # skip test callers
61
- ucn blast helper --expand-unverified # follow unverified edges too (marked ⚠, possible impact)
62
- ```
70
+ Use `trace` instead of repeatedly calling `about` down a pipeline. Use `blast` instead of repeatedly calling `impact` up a caller chain.
63
71
 
64
- The tree trunk is confirmed-evidence-only; dispatch-possible/ambiguous caller candidates appear in an `UNVERIFIED EDGES` section (see "Reading Tiered Output" below).
72
+ ## Breaking-change protocol
65
73
 
66
- ### 4. `trace` Understand execution flow (downward)
74
+ Before renaming, changing parameters, or changing behavior:
67
75
 
68
- Draws the call tree downward from any function. Compact by default; setting `--depth=N` shows the full tree to that depth with all children expanded.
76
+ 1. Pin the exact definition with a handle.
77
+ 2. Run `impact`; review every unverified and warning entry.
78
+ 3. Run `blast` for transitive impact when behavior changes.
79
+ 4. Run `affected-tests`; treat “uncovered” as a test-planning signal, not proof of no coverage.
80
+ 5. Make the change.
81
+ 6. Run `verify`, the relevant compiler or type checker, and the selected tests.
82
+ 7. Run `ucn check` to reconcile the repository diff.
69
83
 
70
- ```bash
71
- ucn trace generate_report # compact (depth 3, limited breadth)
72
- ucn trace generate_report --depth=5 # full tree to depth 5, all children shown
73
- ucn trace generate_report --all # all children at default depth
74
- ```
84
+ UCN augments the compiler and tests; it does not replace them.
75
85
 
76
- Shows the entire pipeline — what `generate_report` calls, what those functions call, etc. — as an indented tree. No file reading needed. Invaluable for understanding orchestrator functions or entry points.
86
+ ## Deletion protocol
77
87
 
78
- **Prefer `trace` over chained `about` calls.** If you find yourself running `ucn about` 4–5 times in a row to follow a call chain (entry → leaves), one `ucn trace <fn> --depth=N` returns the same information in a single call. Use `--depth=N` to limit how deep the tree goes.
88
+ Treat `deadcode` as a candidate generator. Before deleting a symbol:
79
89
 
80
- ### 5. `fn` / `class` Extract without reading the whole file
90
+ 1. Run `ucn deadcode`, then pin the candidate.
91
+ 2. Run `ucn usages <name>` to inspect calls, imports, type references, and non-call references.
92
+ 3. Run `ucn impact <handle>` and inspect `ACCOUNT`, `CONTRACT`, warnings, unverified sites, and beyond-text callers.
93
+ 4. Run `ucn entrypoints` and consider framework registration, reflection, serialization, dependency injection, public API use, and external consumers.
94
+ 5. Run `ucn doctor --deep`; inspect index health, evidence readiness, and the deletion review requirement.
95
+ 6. Delete only with corroborating compiler/type-checker and test evidence.
81
96
 
82
- Pull one or more functions out of a large file. Supports comma-separated names for bulk extraction.
97
+ Never delete solely because `deadcode` or an observed-text-zero contract reports zero callers.
83
98
 
84
- ```bash
85
- ucn fn handle_request --file=api # --file disambiguates when name exists in multiple files
86
- ucn fn parse,format,validate # Extract multiple functions in one call
87
- ucn class MarketDataFetcher
88
- ```
99
+ ## Ambiguity and dispatch
89
100
 
90
- ### 6. `deadcode` Find unused code
101
+ - Prefer handles over a plain symbol name.
102
+ - Use `--class-name=<Class>` or `--file=<pattern>` only when a handle is unavailable.
103
+ - Treat `possible-dispatch`, `method-ambiguous`, `alias-call`, and `call-not-resolved` as review-required.
104
+ - Tree trunks contain confirmed edges. Unverified edges are separate and are not expanded unless `--expand-unverified` is requested.
105
+ - Following an unverified edge produces a possible-impact chain, not a confirmed chain.
91
106
 
92
- Lists all functions and classes with zero callers across the project — class-like symbols (classes, structs, interfaces, traits, enums, namespaces) are audited alongside functions. Framework entry points (Express routes, Spring controllers, Celery tasks, etc.) and exported/public API symbols — including methods of exported classes in JS/TS/Python — are automatically excluded (`--include-exported` audits them). Interface/trait method declarations are labeled `[declared on interface X — contract surface, not executable code]`: unreferenced is true, but deleting one changes the API contract, not dead logic. Symbols whose only call sites sit inside their own same-name definitions are claimed and marked `[only self-references — recursive]` — the group is unreachable from outside.
107
+ ## Efficient output
93
108
 
94
- ```bash
95
- ucn deadcode # Everything
96
- ucn deadcode --exclude=test # Skip test files (most useful)
97
- ucn deadcode --include-decorated # Include framework-registered functions
98
- ucn deadcode --include-exported # Audit exported/public API symbols too
99
- ```
109
+ - Use `--compact` for agent context and `--json` for automation.
110
+ - Use `--exclude=test` only for a production-only view; rerun without it before a breaking change.
111
+ - Use `--all` when a section says results were capped.
112
+ - Use `--no-cache` after edits if cache freshness is in doubt.
113
+ - Use `ucn search` for text or structural queries; use ordinary repository search for file names and unsupported syntax.
100
114
 
101
- ### 7. `brief` One-screen "before-I-touch-this" summary
102
-
103
- AST-only summary of a function: typed signature, first sentence of docstring,
104
- side-effect classification (fs/network/process/global_mutation), and complexity
105
- metrics (branches, depth, line count). Lighter than `about`, more useful than
106
- `fn` when you don't need the body.
107
-
108
- ```bash
109
- ucn brief fetch_user
110
- # fetch_user(user_id: int): dict
111
- # svc.py:4-8 (5 lines)
112
- # "Fetch a user from the API."
113
- # async: no | side_effects: [fs, network, process] | complexity: branches=2, depth=2
114
- ```
115
-
116
- ### 8. `doctor` — Project trust report
117
-
118
- One command that tells you how much UCN trusts the index for this project:
119
- file/symbol counts, language breakdown, dynamic-import / eval / reflection
120
- blind spots, parse failures, and a verdict (HIGH/MEDIUM/LOW). Add `--deep` to
121
- sample resolution coverage and bucket edges by confidence.
122
-
123
- ```bash
124
- ucn doctor # fast: counts + blind spots + verdict
125
- ucn doctor --deep # also samples resolution coverage
126
- ucn doctor --in=src/core # scope to a subtree
127
- ```
128
-
129
- ### 9. `check` — Pre-commit summary
130
-
131
- Composes `diff-impact` + `verify` + `affected-tests` into one output. Lists
132
- changed/added/deleted functions, flags signature drift across call sites,
133
- calls out new functions with no callers, and recommends which tests to run.
134
-
135
- ```bash
136
- ucn check # vs HEAD
137
- ucn check --base=main # vs main branch
138
- ucn check --staged # only staged changes
139
- ```
140
-
141
- ### 10. `entrypoints` — Detect framework entry points
142
-
143
- Lists functions registered as framework handlers (HTTP routes, DI beans, job schedulers, etc.). Detects patterns across Express, FastAPI, Flask, Spring, Gin, Actix, Celery, pytest, and more.
144
-
145
- ```bash
146
- ucn entrypoints # All detected entry points (tests included by default)
147
- ucn entrypoints --type=http # HTTP routes only
148
- ucn entrypoints --framework=express # Specific framework
149
- ucn entrypoints --file=routes/ # Scoped to files
150
- ucn entrypoints --exclude-tests # Hide test fixtures (JUnit @Test, pytest, Rust #[test], etc.)
151
- ```
152
-
153
- ### 11. `orient` — First command in a new repo
154
-
155
- One screen: size + language mix, densest directories, most-called production functions, entry-point counts, and the trust verdict. Composes what would otherwise take four calls (`toc` + `stats --hot` + `entrypoints` + `doctor`).
156
-
157
- ```bash
158
- ucn orient # run this before anything else in an unfamiliar codebase
159
- ucn orient --top=15 # longer dir/hot lists
160
- ```
161
-
162
- The `Next:` line suggests concrete follow-ups, starting with `about` on the hottest production function.
163
-
164
- ## When to Use the Other Commands
165
-
166
- | Situation | Command | What it does |
167
- |-----------|---------|-------------|
168
- | Quick callers + callees list | `ucn context <name>` | Who calls it and what it calls. Results are numbered for `expand`. Use instead of `about` when you just need the call graph, not source code |
169
- | Need function + all its helpers inline | `ucn smart <name>` | Returns function source with every helper it calls expanded below it. Use instead of `about` when you need code, not metadata |
170
- | Full transitive blast radius | `ucn blast <name> --depth=5` | Callers of callers — the full chain of what breaks if you change something |
171
- | How execution reaches a function | `ucn reverse-trace <name>` | Walk UP callers to entry points (★ marked). Shows how code flows to this function. Default depth=5 |
172
- | Which tests to run after a change | `ucn affected-tests <name>` | Blast + test detection: shows test files, coverage %, uncovered functions. Use `--depth=N` to control depth |
173
- | What changed and who's affected | `ucn diff-impact --base=main` | Shows changed functions + their callers from git diff |
174
- | Checking if a refactor broke signatures | `ucn verify <name>` | Validates all call sites match the function's parameter count |
175
- | Understanding a file's role in the project | `ucn imports <file>` | What it depends on |
176
- | Understanding who depends on a file | `ucn exporters <file>` | Which files import it |
177
- | See what a file exports | `ucn file-exports <file>` | All exported functions, classes, variables with signatures |
178
- | Quick project overview | `ucn toc` | Every file with function/class counts and line counts |
179
- | Just entered an unfamiliar repo | `ucn orient` | One screen: size, top dirs, hot functions, entry points, trust verdict. Run it first |
180
- | Project complexity stats | `ucn stats` | File counts, symbol counts, lines by language. `--functions` for per-function line counts. `--hot --top=N` for the most-called functions (orientation primitive on a new repo) |
181
- | Find by glob pattern | `ucn find "handle*"` | Locate definitions matching a glob (supports * and ?) |
182
- | Text search with context | `ucn search term --context=3` | Like grep -C 3, shows surrounding lines |
183
- | Regex search (default) | `ucn search '\d+'` | JavaScript regex (V8 engine). See "Regex notes" below for syntax — alternation is `a|b`, not grep-style |
184
- | Text search filtered | `ucn search term --exclude=test` | Search only in matching files |
185
- | Structural search (index) | `ucn search --type=function --param=Request` | Query the symbol table, not text. Finds functions by param, return type, decorator, etc. |
186
- | Find all db.* calls | `ucn search --type=call --receiver=db` | Search call sites by receiver — something grep can't do |
187
- | Find exported functions | `ucn search --type=function --exported` | Only exported/public symbols |
188
- | Find unused symbols | `ucn search --type=function --unused` | Mini deadcode: zero callers |
189
- | Find decorated functions | `ucn search --decorator=Route` | Functions/classes with a specific decorator/annotation |
190
- | Finding all usages (not just calls) | `ucn usages <name>` | Groups into: definitions, calls, imports, type references |
191
- | Finding sibling/related functions | `ucn related <name>` | Name-based + structural matching (same file, shared deps). Not semantic — best for parse/format pairs |
192
- | Preview a rename or param change | `ucn plan <name> --rename-to=new_name` | Shows what would change without doing it |
193
- | File-level dependency tree | `ucn graph <file> --depth=1` | Visual import tree. Setting `--depth=N` expands all children. Can be noisy — use depth=1 for large projects. For function-level flow, use `trace` instead |
194
- | Are there circular dependencies? | `ucn circular-deps` | Detect circular import chains. `--file=<pattern>` filters to cycles involving a file. `--exclude=test` skips test files |
195
- | What are the framework entry points? | `ucn entrypoints` | Lists all detected routes, DI beans, tasks, etc. Filter: `--type=http`, `--framework=express` |
196
- | Polyglot route ↔ request matching | `ucn endpoints --bridge` | Server routes (Express/Fastify/Koa/NestJS/Flask/FastAPI/Spring/JAX-RS/Gin/Echo/Chi/Fiber/axum/actix/Next.js) ↔ client requests (fetch/axios/requests/httpx/RestTemplate/WebClient/reqwest). Match confidence: EXACT, PARTIAL, UNCERTAIN. Filter with `--method`, `--prefix`, `--server-only`, `--client-only`, `--unmatched`, `--hide-uncertain` |
197
- | Find which tests cover a function | `ucn tests <name>` | Test files and test function names. Scope with `--file`, `--class-name`, `--exclude`, `--calls-only` |
198
- | Extract specific lines from a file | `ucn lines 10-20 --file=<file>` | Pull a line range without reading the whole file |
199
- | Find type definitions | `ucn typedef <name>` | Interfaces, enums, structs, traits, type aliases |
200
- | See a project's public API | `ucn api` or `ucn api --file=<file>` | All exported/public symbols with signatures |
201
- | Drill into context results | `ucn expand <N>` | Show source code for item N from a previous `context` call |
202
- | Best usage example of a function | `ucn example <name>` | Finds and scores the best call site with surrounding context |
203
- | Debug a stack trace | `ucn stacktrace --stack="<trace>"` | Parses stack frames and shows source context per frame |
204
- | Quick look before touching a function | `ucn brief <name>` | Signature + docstring + side effects + complexity, one screen |
205
- | Project trust report | `ucn doctor [--deep]` | Index coverage, blind spots, parse failures, verdict |
206
- | Pre-commit summary | `ucn check [--base=main]` | Changed funcs + signature drift + affected tests in one shot |
207
- | Find missing-await bugs | `ucn audit-async` | Lists async calls inside async functions that lack `await`. JS/TS/Python only. Filter with `--file`, `--exclude`, `--limit` |
208
-
209
- ## Regex Notes (`search` command)
210
-
211
- `search` uses **JavaScript regex** (the V8 engine), not grep BRE/ERE. Common gotchas:
212
-
213
- - Alternation is `a|b`, **not** `a\|b`. `ucn search "flask|fastapi|django"` works; `ucn search "flask\|fastapi\|django"` matches the literal string.
214
- - `(`, `[`, `{` outside character classes do **not** need escaping for literal match in most cases — but normal JS regex semantics apply (you can still escape them for clarity).
215
- - Wrap the pattern in single quotes so the shell does not interpret special characters (`*`, `?`, `\`, `$`, etc.).
216
- - Default is case-insensitive; pass `--case-sensitive` to flip.
217
- - `--no-regex` forces literal-string search if you need to match regex metacharacters as text without escaping.
218
-
219
- ## Reading Call-Site Patterns
220
-
221
- `verify`, `impact`, and `about` annotate call sites with structural classification flags. Watch for these in summary lines (`Patterns: 4 in try, 4 in callback`) and per-call-site entries:
222
-
223
- | Flag | What it means | Why it matters |
224
- |------|--------------|---------------|
225
- | `inLoop` | Call is inside a `for`/`while`/comprehension | N+1 query risk, repeated work, performance hot path |
226
- | `inTry` | Call is wrapped in try/catch (or equivalent) | Errors are handled — different from "must fix" code paths |
227
- | `inCallback` | Call sits inside a callback/lambda/closure that's not the enclosing function | Async deferred work, may run on a different stack frame |
228
- | `inTestCase` | Call originates from inside a test function | Isolate production callers from test setup |
229
- | `awaited` | Call's parent is `await` / `Promise.then` (JS/TS/Python) | Confirms async coordination — its absence on async callees signals a missing-await bug |
230
-
231
- `audit-async` is the focused tool for the `awaited=false` case across an entire async function body.
232
-
233
- ## Reading Tiered Output (about / context / impact / trace / blast / reverse-trace / affected-tests / diff-impact / verify / plan / check)
234
-
235
- Caller answers are a **partition of every text occurrence** of the symbol — nothing is silently hidden. Sections:
236
-
237
- - `CALLERS — CONFIRMED (N, X prod + Y test):` — edges with binding/receiver/import evidence. Prod callers listed first, then a `test callers:` subheader. An `evidence:` line aggregates resolution labels for the section.
238
- - `CALLERS — UNVERIFIED (N) — call syntax, no binding/receiver evidence:` — name-matched call sites the engine could not verify, one line each with the reason (`method-no-evidence`, `ambiguous-binding`, `call-not-resolved`). Capped at 10; `--all` lifts the cap. **Treat these as possible callers when refactoring.**
239
- - `NON-CALL OCCURRENCES: N (...)` — imports/definitions/references/other-text, counts only (drill in with `ucn usages <name>`).
240
- - `ACCOUNT:` — the reconciliation line. Every ground line is in exactly one bucket; `0 unaccounted` means the partition is complete. `+N beyond-text callers` are alias-resolved call sites plain text search would miss.
241
- - `WARNING: N unparsed file(s) ...` — files containing the symbol that failed to parse. Their lines were NOT analyzed — fall back to text search for those files.
242
- - `FILTERED: N hidden by flags` — entries your display flags hid (they still count in ACCOUNT).
243
-
244
- **Trust rules:** a CONFIRMED(0) + UNVERIFIED(0) answer with `0 unaccounted` and no WARNING means the symbol genuinely has no callers — safe to act on, same as a clean grep. Any UNVERIFIED entries or WARNINGs mean: verify those sites before a breaking change.
245
-
246
- Resolution labels in `evidence:` lines (high to low): `exact-binding` (0.98, import/binding evidence) · `same-class` (0.92) · `receiver-hint` (0.80, inferred receiver type) · `scope-match` (0.65, import/receiver-binding scope evidence) · `name-only` (0.40) · `uncertain` (0.25). Confirmed tier = scope-match and above. JSON output keeps per-edge decimals plus `tier`.
247
-
248
- Flags: `--min-confidence=0.7` filters confirmed edges (hidden count appears in FILTERED). `--include-uncertain` and `--include-methods` have **no effect** on tiered commands (about/context/impact/trace/blast/reverse-trace/affected-tests/diff-impact/verify/plan/smart) — everything is always shown, tiered by evidence.
249
-
250
- ### Refactor commands run the same contract (v4)
251
-
252
- - `verify` arg-checks the **confirmed** band only; candidates without evidence render in `UNVERIFIED CALL SITES (N)` with reasons and are NOT arg-checked (they may target another symbol). A wrong-arity method call with binding evidence is flagged **by default** now. The `ACCOUNT:` line reconciles.
253
- - `plan` plans changes for confirmed sites; `UNVERIFIED CALL SITES` lists sites that MAY also need the change — review them before refactoring. Plan and verify agree by construction.
254
- - `diff-impact` reports per-changed-function confirmed `Callers` + `Unverified call sites` + a per-symbol `ACCOUNT:` line. `check` shows `N callers (+M unverified)` per changed function; ORPHAN requires zero candidates in BOTH tiers.
255
- - `context`/`smart` also account the **callee** side: `CALLEES — UNVERIFIED (N)` entries + a `CALLEE ACCOUNT:` arithmetic line.
256
-
257
- ### Advisory commands self-label
258
-
259
- `related`, `example`, `stacktrace`, and `endpoints --bridge` print an `Advisory:` line (and carry an `advisory` field in JSON): their answers are ranked heuristics, not verified claims. Contracted commands carry accounts; advisory commands say so — there is no third category.
260
-
261
- ### Tree commands (trace / blast / reverse-trace / affected-tests)
262
-
263
- The tree trunk holds **confirmed edges only**. Unverified caller candidates render in an `UNVERIFIED EDGES` section with parent attribution (`at <node> (hop N): file:line [enclosing fn] (reason)`) and are **not expanded by default** — pass `--expand-unverified` to follow them; every downstream node is then marked `[⚠ via <reason>]` / `[⚠ unverified chain]` and counted as *possibly affected*, never confirmed. Unresolved callee calls (`trace` down) render as `[unverified] name — reason` leaves under their node. Reconciliation lines:
264
-
265
- - `ACCOUNT:` — the root hop's text-ground partition (same as context/impact).
266
- - `TREE ACCOUNT:` — interior conservation: nodes expanded, confirmed/unverified/excluded edge counts by reason, depth-limit cuts.
267
- - `CALLEE ACCOUNT:` (trace down) — every call site in every expanded node lands in confirmed/unverified/external/excluded/filtered.
268
-
269
- `reverse-trace` marks `★ entry point` only when a node has **zero candidates in both tiers**; zero confirmed with unverified candidates shows `⚠ no confirmed callers — N unverified` instead. `affected-tests` splits its answer into the confirmed band (`Test files to run`, coverage, `Uncovered`) and a `POSSIBLY AFFECTED` band (functions + test files reachable only through unverified chains).
270
-
271
- ## Symbol Handles (stable IDs)
272
-
273
- Every result that lists a symbol emits a **handle** in the form `relativePath:line:name` (e.g. `core/api.ts:42:handler`). Pass it back to any name-accepting command and resolution is pinned to that exact definition — no name disambiguation, no `--file` needed.
274
-
275
- ```bash
276
- ucn find handler # → emits src/api.ts:42:handler
277
- ucn brief src/api.ts:42:handler # pins to that exact one
278
- ucn impact src/api.ts:42:handler # same
279
- ```
280
-
281
- The shorter `relativePath:line` form (no `:name`) also works — UCN looks up the symbol by location. Plain names (`handler`) still work for the fuzzy/heuristic path.
282
-
283
- ## Command Format
284
-
285
- ```
286
- ucn [target] <command> [name] [--flags]
287
- ```
288
-
289
- **Target** (optional, defaults to current directory):
290
- - Omit — scans current project (most common)
291
- - `path/to/file.py` — single file
292
- - `path/to/dir` — specific directory
293
- - `"src/**/*.py"` — glob pattern (quote it)
294
-
295
- ## Key Flags
296
-
297
- | Flag | When to use it |
298
- |------|---------------|
299
- | `--class-name=X` | Scope to specific class (e.g., `--class-name=Repository` for method `save`). Works with `about`, `context`, `impact`, `blast`, `smart`, `trace`, `reverse-trace`, `example`, `related`, `brief`, `find`, `usages`, `tests`, `affected-tests`, `fn`, `verify`, `plan`, `typedef` |
300
- | `--file=<pattern>` | Disambiguate when a name exists in multiple files (e.g., `--file=api`) |
301
- | `--exclude=test,mock` | Focus on production code only |
302
- | `--in=src/core` | Limit search to a subdirectory |
303
- | `--depth=N` | Control tree depth for `trace`, `graph`, and detail level for `find` (default 3). Also expands all children — no breadth limit |
304
- | `--all` | Expand truncated sections. Applies to `about`, `blast`, `trace`, `reverse-trace`, `related`, `find`, `toc`, `fn`, `class`, `graph`, `diff-impact` |
305
- | `--expand-unverified` | `blast`/`reverse-trace`: follow unverified caller edges in the tree. Downstream nodes are marked as unverified chains — possible, not confirmed, impact |
306
- | `--include-tests` | Include test files in usage counts (`about`) and results (`find`, `usages`, `deadcode`). Callers always include tests. |
307
- | `--exclude-tests` | Exclude test entries from `entrypoints` (tests are included by default since they ARE entry points). |
308
- | `--include-methods` | Include `obj.method()` callee expansion in `trace`/`smart`. No effect on caller-direction commands (`about`/`context`/`impact`/`verify`/`blast`/`reverse-trace`/`affected-tests`) — method calls are always analyzed and tiered by receiver evidence |
309
- | `--base=<ref>` | Git ref for diff-impact (default: HEAD) |
310
- | `--staged` | Analyze staged changes (diff-impact) |
311
- | `--no-cache` | Force re-index after editing files |
312
- | `--clear-cache` | Delete cached index entirely before running |
313
- | `--context=N` | Lines of surrounding context in `usages`/`search` output |
314
- | `--no-regex` | Force plain text search (regex is default) |
315
- | `--functions` | Show per-function line counts in `stats` (complexity audit) |
316
- | `--hot` | List top N most-called functions in `stats` (use with `--top=N`, default 10). Best orientation primitive when entering a new repo |
317
- | `--diverse` | Cluster `example` call sites by argument shape and return one representative per cluster (use with `--top=N`, default 3) |
318
- | `--git` | Attach git enrichment to `about` / `brief`: last commit (ISO + author) and recent change count (last 30 days). Skipped silently when not a git repo |
319
- | `--json` | Machine-readable JSON output. Most commands wrap in `{meta, data}` (e.g., `find`, `deadcode`, `context`, `verify`, `plan`, `diff-impact` — completeness signals and the ACCOUNT live in `meta`); `about` and `impact` return their full result object flat — check each command's output shape |
320
- | `--code-only` | Exclude matches in comments and strings (`search`/`usages`) |
321
- | `--with-types` | Include related type definitions in `smart`/`about` output |
322
- | `--detailed` | Show full symbol listing per file in `toc` |
323
- | `--top-level` | Show only top-level functions in `toc` (exclude nested/indented) |
324
- | `--top=N` | Limit result count (default: 10 for most commands) |
325
- | `--limit=N` | Limit result count for `find`, `usages`, `toc`, `search`, `deadcode`, `entrypoints`, `endpoints`, `diff-impact`, `check`, `api`, `doctor`, `audit-async` |
326
- | `--max-files=N` | Max files to index (for large projects with 10K+ files) |
327
- | `--max-lines=N` | Max source lines for `class` (large classes show summary by default) |
328
- | `--case-sensitive` | Case-sensitive text search (default: case-insensitive) |
329
- | `--exact` | Exact name match only in `find`/`typedef` (no substring) |
330
- | `--include-uncertain` | No effect on tiered commands — unverified candidates are always shown in their own section with reasons |
331
- | `--hide-confidence` | Hide confidence scores (shown by default) in `context`/`about` |
332
- | `--min-confidence=N` | Filter edges below confidence threshold (e.g., `--min-confidence=0.7` keeps only high-confidence edges) |
333
- | `--calls-only` | Only show call/test-case matches in `tests` (skip file-level results) |
334
- | `--add-param=<name>` | Add a parameter (`plan` command). Combine with `--default=<value>` |
335
- | `--remove-param=<name>` | Remove a parameter (`plan` command) |
336
- | `--rename-to=<name>` | Rename a function (`plan` command) |
337
- | `--include-exported` | Include exported symbols in `deadcode` results |
338
- | `--include-decorated` | Include decorated/annotated symbols in `deadcode` results |
339
- | `--framework=X` | Filter `entrypoints` by framework (e.g., `express`, `spring`, `celery`) |
340
- | `--bridge` | Match server routes to client requests (`endpoints`). Confidence tiers: EXACT, PARTIAL, UNCERTAIN |
341
- | `--server-only` | Only list server routes (`endpoints`) |
342
- | `--client-only` | Only list client requests (`endpoints`) |
343
- | `--unmatched` | Only show routes/requests with no match (`endpoints`, pair with `--bridge`) |
344
- | `--method=GET` | Filter by HTTP method (`endpoints`) |
345
- | `--prefix=/api` | Filter routes/requests by path prefix (`endpoints`) |
346
- | `--hide-uncertain` | Hide UNCERTAIN-confidence bridges (`endpoints`) |
347
- | `--type=<kind>` | Structural search: `function`, `class`, `call`, `method`, `type`. Triggers index query instead of text grep |
348
- | `--param=<name>` | Structural search: filter by parameter name or type (e.g., `--param=Request`) |
349
- | `--receiver=<name>` | Structural search: filter calls by receiver (e.g., `--receiver=db` for all db.* calls) |
350
- | `--returns=<type>` | Structural search: filter by return type (e.g., `--returns=error`) |
351
- | `--decorator=<name>` | Structural search: filter by decorator/annotation (e.g., `--decorator=Route`) |
352
- | `--exported` | Structural search: only exported/public symbols |
353
- | `--unused` | Structural search: only symbols with zero callers |
354
- | `--no-follow-symlinks` | Don't follow symbolic links during file discovery |
355
- | `--workers=N` | Parallel build workers (auto-detect by default; `0` to disable; env: `UCN_WORKERS`) |
356
- | `--deep` | `doctor` only: sample resolution coverage. Slower but produces confidence histogram. |
357
- | `--compact` | One-line-per-item output for `about`/`context`/`find`/`usages`/`impact`. Halves token cost; same info. |
358
-
359
- ## Workflow Integration
360
-
361
- **Investigating a bug:**
362
- ```bash
363
- ucn about problematic_function # Understand it fully
364
- ucn trace problematic_function --depth=2 # See what it calls
365
- ```
366
-
367
- **Before modifying a function:**
368
- ```bash
369
- ucn impact the_function # Who will break? (direct callers)
370
- ucn blast the_function # Who will break? (full transitive chain)
371
- ucn affected-tests the_function # Which tests to run after the change?
372
- ucn smart the_function # See it + its helpers
373
- # ... make changes ...
374
- ucn verify the_function # Did all call sites survive?
375
- ```
376
-
377
- **Before committing:**
378
- ```bash
379
- ucn diff-impact # What changed vs HEAD + who calls it
380
- ucn diff-impact --base=main # What changed vs main branch
381
- ucn diff-impact --staged # Only staged changes
382
- ```
383
-
384
- **Periodic maintenance:**
385
- ```bash
386
- ucn deadcode --exclude=test # What can be deleted?
387
- ucn toc # Project overview
388
- ```
115
+ Read [references/commands.md](references/commands.md) when a less common command or flag is needed. Read [references/trust-contract.md](references/trust-contract.md) before building automation that gates changes on UCN output.
@@ -0,0 +1,93 @@
1
+ # UCN command reference
2
+
3
+ ## Navigation and extraction
4
+
5
+ | Command | Purpose |
6
+ |---|---|
7
+ | `orient` | Repository size, languages, hot symbols, entry points, and readiness summary |
8
+ | `toc` | Files and symbol counts; add `--detailed` for symbol listings |
9
+ | `find <glob>` | Find definitions and obtain stable handles |
10
+ | `fn <handle>` | Extract a function without reading the whole file |
11
+ | `class <handle>` | Extract a class or class-like declaration |
12
+ | `lines <start-end> --file=<path>` | Extract an exact line range |
13
+ | `brief <handle>` | Signature, documentation sentence, effects, and complexity |
14
+ | `about <handle>` | Definition, callers, callees, tests, source, and contracts |
15
+ | `context <handle>` | Compact callers/callees without the full source body |
16
+ | `smart <handle>` | Symbol source plus directly used helpers |
17
+ | `example <handle>` | Best confirmed usage example; abstains when only unverified calls exist |
18
+ | `related <handle>` | Advisory sibling ranking from names, files, and shared dependencies |
19
+ | `expand <N>` | Expand a numbered item from a prior context result |
20
+
21
+ ## Calls, impact, and refactoring
22
+
23
+ | Command | Purpose |
24
+ |---|---|
25
+ | `impact <handle>` | Direct callers grouped by evidence tier |
26
+ | `blast <handle>` | Transitive caller tree |
27
+ | `trace <handle>` | Transitive callee tree |
28
+ | `reverse-trace <handle>` | Caller paths toward entry points |
29
+ | `affected-tests <handle>` | Tests reachable from affected code |
30
+ | `verify <handle>` | Check confirmed call sites against the target signature |
31
+ | `plan <handle> --rename-to=X` | Preview a rename or parameter edit |
32
+ | `diff-impact [--base=REF]` | Changed symbols and caller impact from a Git diff |
33
+ | `check [--base=REF]` | Diff impact, signature checks, and affected tests |
34
+
35
+ ## Search, graph, and maintenance
36
+
37
+ | Command | Purpose |
38
+ |---|---|
39
+ | `search <pattern>` | JavaScript-regex text search; add `--no-regex` for literal search |
40
+ | `search --type=function --param=X` | Structural symbol search |
41
+ | `search --type=call --receiver=db` | Structural call-site search |
42
+ | `usages <name>` | Definitions, calls, imports, types, and other references |
43
+ | `typedef <name>` | Type, interface, enum, struct, trait, class, and record definitions |
44
+ | `tests <name>` | Test files and test functions associated with a symbol |
45
+ | `imports <file>` | Dependencies of a file |
46
+ | `exporters <file>` | Files depending on a file |
47
+ | `file-exports <file>` | Symbols exported by a file |
48
+ | `graph <file> --depth=N` | File dependency tree |
49
+ | `circular-deps` | Import cycles |
50
+ | `api` | Exported/public project surface |
51
+ | `stats` | Project counts; add `--hot` or `--functions` for deeper reporting |
52
+ | `entrypoints` | Framework, route, task, test, and runtime entry points |
53
+ | `endpoints --bridge` | Advisory server-route/client-request matching |
54
+ | `deadcode` | Unreferenced-symbol candidates |
55
+ | `audit-async` | Potential missing-await sites in JS/TS/Python |
56
+ | `stacktrace <text>` | Advisory stack-frame parsing and source lookup |
57
+ | `doctor --deep` | Index health, blind spots, evidence profile, and task readiness |
58
+
59
+ ## Stable symbol identity
60
+
61
+ Commands that list symbols emit handles such as `src/api.ts:42:handler`. Pass the full handle to any command accepting a symbol. `path:line` also works. Handles avoid silently combining same-named definitions.
62
+
63
+ ## Common flags
64
+
65
+ | Flag | Meaning |
66
+ |---|---|
67
+ | `--file=<pattern>` | Scope or disambiguate by file |
68
+ | `--class-name=<name>` | Scope a member to a class |
69
+ | `--in=<directory>` | Limit indexing/query scope |
70
+ | `--exclude=<patterns>` | Exclude matching paths from displayed analysis |
71
+ | `--depth=N` | Control tree depth |
72
+ | `--all` | Lift output caps where supported |
73
+ | `--compact` | Reduce previews and source for agent-efficient output |
74
+ | `--json` | Machine-readable output |
75
+ | `--expand-unverified` | Follow possible caller edges and mark resulting chains unverified |
76
+ | `--base=<ref>` | Compare Git changes with a ref |
77
+ | `--staged` | Analyze staged changes |
78
+ | `--no-cache` | Rebuild instead of loading the project cache |
79
+ | `--clear-cache` | Remove the project cache before rebuilding |
80
+ | `--workers=N` | Set build-worker count; `0` disables parallel build |
81
+ | `--include-exported` | Audit exported symbols in `deadcode` |
82
+ | `--include-decorated` | Audit decorated symbols in `deadcode` |
83
+ | `--code-only` | Exclude comments and strings in text usage/search |
84
+
85
+ `--include-uncertain` and `--include-methods` do not reveal hidden caller evidence in contracted caller commands; those commands already show possible sites in the unverified band. Evidence filters can hide displayed results, so inspect `FILTERED` and rerun without filters before breaking changes.
86
+
87
+ ## Target forms
88
+
89
+ ```text
90
+ ucn [target] <command> [symbol] [flags]
91
+ ```
92
+
93
+ Omit `target` for the current project. A target may be a file, directory, or quoted glob such as `"src/**/*.py"`.