Skip to content

Conversation

@prosdev
Copy link
Collaborator

@prosdev prosdev commented Nov 27, 2025

Summary

Implements #80 - Relationship Queries (dev_refs)

Adds a new MCP tool that queries call relationships for functions and methods.

Changes

Core Types

  • Added CallerInfo and CalleeInfo interfaces to DocumentMetadata
  • callees field stores what a function/method calls
  • Callers computed at query time via reverse lookup

Scanner

  • extractCallees() extracts all call expressions from functions/methods
  • Handles: function calls, method calls, chained calls, constructor calls (new)
  • Resolves file paths via ts-morph symbol lookup
  • Deduplicates by name+line

MCP Adapter

  • New dev_refs tool with parameters:
    • name: Function/method to query
    • direction: callees, callers, or both (default)
    • limit: Max results per direction
  • Outputs formatted markdown with target info, callees, and callers
  • Uses estimateTokensForText for accurate token counting

Utilities

  • Added startTimer() utility for measuring operation duration
  • Reusable across adapters (replaces inline Date.now() pattern)

Example Output

# References for createPlan
**Location:** src/planner.ts:10
**Type:** function

## Callees (what this calls)
- `fetchIssue` at src/github.ts:15
- `analyzeCode` at line 20
- `generateTasks` at src/tasks.ts:30

## Callers (what calls this)
- `runPlan` (function) at src/executor.ts:5
- `main` (function) at src/cli.ts:1

Testing

  • 7 new tests for callee extraction in scanner
  • 18 new tests for RefsAdapter
  • 3 new tests for startTimer utility
  • All 1320 tests passing

Closes #80

…king

Add types to support call graph extraction:
- CallerInfo: name, file, line for functions that call this component
- CalleeInfo: name, file (optional), line for functions this component calls
- Add callees field to DocumentMetadata
- Export new types from scanner module
- Update document preparation to include callees

Note: Callers are computed at query time via reverse lookup of callees.

Part of #80
Use ts-morph to extract call relationships during scanning:
- extractCallees() finds all CallExpression nodes within a function/method
- extractCalleeFromExpression() extracts name, line, and resolved file path
- Handles: function calls, method calls, chained calls, constructor calls
- Deduplicates by name+line to avoid repeated calls
- Resolves file paths via symbol lookup (excludes node_modules)
- Only populates callees field when calls exist

Part of #80
Create RefsAdapter that provides the dev_refs MCP tool:
- Query callees (what a function calls)
- Query callers (what calls a function)
- Query both directions at once
- Format output as readable markdown
- Find best match for function name via semantic search
- Compute callers by reverse lookup through indexed callees

Also adds:
- startTimer() utility for measuring operation duration
- Uses estimateTokensForText for accurate token counting

Registered in MCP server alongside existing adapters.

Part of #80
Scanner tests:
- Extract callees from functions
- Extract callees from methods
- Include line numbers for callees
- No callees for interfaces/type aliases
- Deduplicate callees at same line
- Handle method calls on objects

RefsAdapter tests:
- Tool definition validation
- Input validation (name, direction, limit)
- Callee queries
- Caller queries (reverse lookup)
- Bidirectional queries
- Output formatting (markdown, tokens, duration)
- Not found handling
- Token estimation

Utility tests:
- startTimer() elapsed time
- Multiple elapsed() calls
- Immediate elapsed check

All 1320 tests passing.

Part of #80
@prosdev prosdev merged commit 4117569 into main Nov 27, 2025
1 check passed
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.

Relationship Queries (dev_refs)

1 participant