# get_dependency_path

get_dependency_path finds the shortest dependency path between two files or modules, with common ancestors and bridge suggestions when none exists. Opt-in.

Answers *"how are these two parts of the codebase connected?"* by
walking the import graph. When a direct path exists, returns it with
the edge relationship at each hop. When it doesn't, returns diagnostic
context instead of a bare miss: nearest common ancestors, shared
neighbors, community membership, and bridge-node suggestions, so the
agent can debug an architectural silo instead of giving up. The graph it
walks is the [dependency graph](https://docs.repowise.dev/intelligence/dependency-graph); the
default tools are on [MCP tools](https://docs.repowise.dev/mcp/overview).

## Off by default

Registered but not part of the default tool surface in any mode. Turn
it on per repo:

```yaml
# .repowise/config.yaml
mcp:
  tools: ["+get_dependency_path"]
```

or per launch with `repowise mcp --tools "+get_dependency_path"`. See
[Configuring the tool surface](https://docs.repowise.dev/cli/server#repowise-mcp) for the
full `+`/`-` delta syntax.

## When to call

- **Understanding coupling** between two files or modules that don't
  obviously call each other.
- **Debugging why an expected dependency doesn't show up** in
  `get_context` or `get_risk`.
- **Architectural silos**: when two areas of the codebase should be
  connected but aren't, the visual context on a miss suggests where a
  bridge belongs.

## Parameters

| Name | Type | Default | Description |
|---|---|---|---|
| `source` | string |  | Required. Source file or module path. |
| `target` | string |  | Required. Target file or module path. |
| `repo` | string |  | Repository alias. "all" is not supported. |

## Returns

**When a path exists:**

| Field | Meaning |
|---|---|
| `path` | Ordered list of `{node, relationship}` hops from source to target |
| `distance` | Hop count |
| `explanation` | One-line summary |

**When no direct path exists**, `path` is empty and `distance` is `-1`.
`visual_context` carries the diagnostic instead:

| Field | Meaning |
|---|---|
| `reverse_path` | An object, not a boolean. `{"exists": false}` when no reverse path exists; when one does, `{"exists": true, "path": [...], "distance": N, "note": "..."}` |
| `nearest_common_ancestors` | Up to 5 nodes both source and target reach, ranked by combined distance |
| `shared_neighbors` | Direct neighbors in common |
| `community` | `{source_community, target_community, same_community}`: whether source and target sit in the same architectural community |
| `bridge_suggestions` | High-PageRank nodes that touch both communities, when source and target are in different ones |
| `disconnected` | `true` if source and target are in completely separate weakly-connected components |
| `source_component_size`, `target_component_size` | *(only when `disconnected: true`)* size of each node's weakly-connected component |
| `suggestion` | A one-line, best-effort read of the above (shared dependency, shared neighbor, reverse-only, or genuinely disconnected) |
| `co_change_signal` | *(when present)* source and target aren't import-connected but co-change frequently, suggesting logical coupling instead |

## Example

```python
get_dependency_path(source="src/api/routes.py", target="src/db/models.py")
```

## Things worth knowing

- **Excluded paths error out.** Passing a `source` or `target` matched
  by `exclude_patterns` returns an error instead of a path through
  code the index doesn't track.
- **The graph used is the filtered graph.** Excluded nodes and edges
  never appear in a returned path, a common ancestor, or a bridge
  suggestion.
- **Co-change is a fallback signal, not a substitute.** `co_change_signal`
  only appears on a genuine no-path miss, and only when target is
  literally one of source's recorded co-change partners.

> **Note**
>
> For "what breaks if I change this" instead of "how are these two
> connected", reach for [`get_risk`](https://docs.repowise.dev/mcp/get-risk) or, across repos
> in workspace mode, `get_blast_radius`.
