Skip to content

refactor(analysis): add an Analyzer parent for lineage + graph#13

Open
burrows99 wants to merge 1 commit into
masterfrom
refactor/analyzer-base
Open

refactor(analysis): add an Analyzer parent for lineage + graph#13
burrows99 wants to merge 1 commit into
masterfrom
refactor/analyzer-base

Conversation

@burrows99

Copy link
Copy Markdown
Owner

What

Introduces Analyzer<In, Out> as the shared parent of every analysis in trace-cli, and routes both existing analyses through it.

The parent (src/analysis/Analyzer.ts) fixes one contract: a stable name + analyze(input): Out | Promise<Out> that normalizes raw signal into a domain shape. Abstract, so subclasses narrow In/Out and pick sync or async.

Both analyses now extend it:

Analyzer Extends Kind analyze
LineageAnalyzer Analyzer<TraceEvent[], Lineage[]> runtime values sync — the old compute body
GraphAnalyzer (new) Analyzer<GraphAnalysisInput, CodeGraph> graphical / call-graph async — delegates to the pluggable CodeGraphProvider

Design notes

  • LineageAnalyzer: static compute → instance analyze; the pure summary formatter stays a static helper (it's a view util, not part of the analysis contract).
  • GraphAnalyzer is the analysis-tier seam so the graph command depends on an Analyzer (a sibling to lineage), while the existing CodeGraphProvider / LspCodeGraphProvider stays the swappable backend it delegates to. name mirrors the provider, so the graph.lsp envelope command is unchanged.
  • Call sites updated: RunCommandnew LineageAnalyzer().analyze(...); GraphCommand builds a GraphAnalyzer over the chosen provider and reads analyzer.name.

Verification

  • tsc --noEmit clean (abstract implementations need no override; return-type narrowing holds)
  • full build (CLI + UI) green
  • 77/78 tests pass (1 Postgres round-trip skipped — needs a live DB)
  • added an instanceof Analyzer assertion on both sides + a GraphAnalyzer delegation test that drives a real language server

🤖 Generated with Claude Code

…through it

Introduce `Analyzer<In, Out>` as the shared parent of every analysis: a
stable `name` plus `analyze(input)` that normalizes raw signal into a
domain shape. Both analyses now extend it:

- LineageAnalyzer extends Analyzer<TraceEvent[], Lineage[]> — the runtime
  value analysis (sync). `compute` becomes the instance `analyze`; the
  pure `summary` formatter stays a static helper.
- GraphAnalyzer (new) extends Analyzer<GraphAnalysisInput, CodeGraph> —
  the graphical analysis (async). It delegates the call-hierarchy walk to
  the existing pluggable CodeGraphProvider, so the provider stays the
  swappable backend while `graph` now depends on an Analyzer, like a
  sibling to lineage.

Call sites updated: RunCommand uses `new LineageAnalyzer().analyze(...)`;
GraphCommand builds a `GraphAnalyzer` over the chosen provider and reads
`analyzer.name` for the `graph.<name>` envelope. Exports + tests follow,
with an instanceof-Analyzer assertion on both sides to pin the contract.

Verified: tsc --noEmit clean, full build green, 77/78 tests pass (1
Postgres test skipped — needs a live DB).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings June 19, 2026 11:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a shared Analyzer<In, Out> abstract base class for analysis components and refactors existing lineage analysis to conform to that contract, while adding a new GraphAnalyzer that wraps the code-graph provider behind the same interface. This aligns lineage + graph under a common “analysis” abstraction that commands can depend on.

Changes:

  • Added src/analysis/Analyzer.ts and refactored LineageAnalyzer to extend it (compute → instance analyze, plus stable name).
  • Added GraphAnalyzer as an Analyzer over CodeGraphProvider and updated GraphCommand to use it.
  • Updated exports and tests to validate instanceof Analyzer, analyzer naming, and graph delegation.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/domain.test.js Updates lineage tests to use new LineageAnalyzer().analyze(...) and asserts Analyzer inheritance/name.
test/codegraph.test.js Adds GraphAnalyzer delegation test + asserts Analyzer inheritance/name.
src/index.ts Exposes Analyzer, GraphAnalyzer, and GraphAnalysisInput from the package entrypoint.
src/cli/commands/RunCommand.ts Switches lineage computation call site to new LineageAnalyzer().analyze(...).
src/cli/commands/GraphCommand.ts Refactors graph command to depend on GraphAnalyzer and use analyzer.name for provenance.
src/analysis/LineageAnalyzer.ts Converts lineage analysis into an Analyzer subclass with stable name + instance analyze.
src/analysis/GraphAnalyzer.ts Introduces graph analysis layer delegating to a CodeGraphProvider.
src/analysis/Analyzer.ts Adds shared abstract base defining name + analyze contract (sync or async).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +38 to 40
const analyzer = new GraphAnalyzer(createCodeGraphProvider(request.provider));
const diagnostics: Diagnostic[] = [];
let data = new TraceData({});
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.

2 participants