Skip to content

Commit fd3983a

Browse files
committed
feat(core): add CallerInfo and CalleeInfo types for relationship tracking
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
1 parent d267a21 commit fd3983a

File tree

4 files changed

+34
-1
lines changed

4 files changed

+34
-1
lines changed

packages/core/src/indexer/utils/documents.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ export function prepareDocumentsForEmbedding(documents: Document[]): EmbeddingDo
4141
docstring: doc.metadata.docstring,
4242
snippet: doc.metadata.snippet,
4343
imports: doc.metadata.imports,
44+
callees: doc.metadata.callees,
4445
},
4546
}));
4647
}
@@ -76,6 +77,7 @@ export function prepareDocumentForEmbedding(doc: Document): EmbeddingDocument {
7677
docstring: doc.metadata.docstring,
7778
snippet: doc.metadata.snippet,
7879
imports: doc.metadata.imports,
80+
callees: doc.metadata.callees,
7981
},
8082
};
8183
}

packages/core/src/scanner/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
export { MarkdownScanner } from './markdown';
44
export { ScannerRegistry } from './registry';
55
export type {
6+
CalleeInfo,
7+
CallerInfo,
68
Document,
79
DocumentMetadata,
810
DocumentType,

packages/core/src/scanner/types.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ export type DocumentType =
99
| 'method'
1010
| 'documentation';
1111

12+
/**
13+
* Information about a function/method that calls this component
14+
*/
15+
export interface CallerInfo {
16+
/** Name of the calling function/method */
17+
name: string;
18+
/** File path where the call originates */
19+
file: string;
20+
/** Line number of the call site */
21+
line: number;
22+
}
23+
24+
/**
25+
* Information about a function/method called by this component
26+
*/
27+
export interface CalleeInfo {
28+
/** Name of the called function/method */
29+
name: string;
30+
/** File path of the called function (if resolved) */
31+
file?: string;
32+
/** Line number of the call within this component */
33+
line: number;
34+
}
35+
1236
export interface Document {
1337
id: string; // Unique identifier: file:name:line
1438
text: string; // Text to embed (for vector search)
@@ -29,6 +53,10 @@ export interface DocumentMetadata {
2953
snippet?: string; // Actual code content (truncated if large)
3054
imports?: string[]; // File-level imports (module specifiers)
3155

56+
// Relationship data (call graph)
57+
callees?: CalleeInfo[]; // Functions/methods this component calls
58+
// Note: callers are computed at query time via reverse lookup
59+
3260
// Extensible for future use
3361
custom?: Record<string, unknown>;
3462
}

packages/core/src/vector/types.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* Vector storage and embedding types
33
*/
44

5-
import type { DocumentType } from '../scanner/types';
5+
import type { CalleeInfo, DocumentType } from '../scanner/types';
66

77
/**
88
* Document to be embedded and stored
@@ -33,6 +33,7 @@ export interface SearchResultMetadata {
3333
docstring?: string; // Documentation comment
3434
snippet?: string; // Actual code content (truncated if large)
3535
imports?: string[]; // File-level imports (module specifiers)
36+
callees?: CalleeInfo[]; // Functions/methods this component calls
3637
// Allow additional custom fields for extensibility (e.g., GitHub indexer uses 'document')
3738
[key: string]: unknown;
3839
}

0 commit comments

Comments
 (0)