Skip to content

fix(architecture): stop a file's import-only callees from adding weight - #43

Merged
inth3shadows merged 1 commit into
masterfrom
arch-file-node-imports
Sep 27, 2026
Merged

inth3shadows merged 1 commit into
masterfrom
arch-file-node-imports

Conversation

@inth3shadows

Copy link
Copy Markdown
Owner

Follow-up (d) from #39's review.

codegraph lists every symbol a file imports among the file node's callees (imports edges). So a function main.ts imports and calls only inside its own run() weighed 2 on main.ts → alpha.ts: 1 for the call, 1 for the import.

  • The fork's per-definition slices carry edges[] with a kind per edge. New importOnlyIds returns callees whose every edge is imports, and probeSymbolCallees drops them on the id-matched and same-named-file routes.
  • A real top-level call from the file (gamma();, or one inside an anonymous callback) is a calls edge to the same target, so it is kept.
  • npm codegraph (through 1.6.0) has the same +1 but returns no edges, so nothing changes there. TECHNICAL.md Known Limitations documents the fork/npm weight difference.

Measured on a TS fixture: master drew weight 5, this draws 4 (the 4 real calls). This repo's CommonJS docs/architecture.svg is unchanged: --check passes locally.

Local: node test/run.js 183 passed, 0 failed (fork codegraph).

codegraph lists a file's imported symbols among the file node's callees,
so a function imported and called only from inside one of the file's
functions weighed 2 on the file edge. With per-definition JSON each slice
carries edges[] with a kind; importOnlyIds drops callees reached only by
imports edges, while top-level calls (a calls edge to the same target)
are kept. npm codegraph has no edges[], so it still counts the import.
@inth3shadows
inth3shadows merged commit dbdccd4 into master Sep 27, 2026
7 checks passed
@inth3shadows
inth3shadows deleted the arch-file-node-imports branch September 27, 2026 02:01
inth3shadows added a commit that referenced this pull request Sep 27, 2026
…#46)

Two defects in `--architecture`'s per-symbol CLI probes. They were found
by comparing the probes against codegraph's index directly (groundwork
for the direct index read, next PR).

- **Import nodes were probed by name.** An import statement's node has
no callee edges: 0 of 3,659 on codegraph's repo, 0 of 715 on terse. But
its text as a name (`terse.capture`, `../src/mcp/tools`) resolves to
*another* symbol and borrows its callees, which fabricates file edges.
`probeFileEdges` now skips import nodes; this also removes thousands of
wasted probes on TS repos.
- **#43's import-only filter dropped real calls.** It trusted
per-definition `edges[]`, but that list holds ONE edge per callee
(whichever codegraph found first). So an `imports` entry can hide an
`instantiates`/`references` edge to the same target (codegraph's repo: a
test that imports and instantiates `ToolHandler` lost the edge). The
filter is removed from the CLI path: an import-only callee now
overcounts its file edge by 1 instead of a real call going missing.
TECHNICAL.md Known Limitations is rewritten to match.

Regression tests: both shapes from the real failures
(`probeSymbolCallees` keeps an imported callee whose one listed edge is
`imports`; `probeFileEdges` never probes an import node).

Local: `node test/run.js` 188 passed, 0 failed (fork codegraph);
`--check` on `docs/architecture.svg` is up to date.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant