@zipbul/gildash 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/README.ko.md +38 -7
  2. package/README.md +39 -6
  3. package/dist/index.js +7 -5
  4. package/dist/index.js.map +43 -28
  5. package/dist/migrations/0003_majestic_mongu.sql +1 -0
  6. package/dist/migrations/0004_cool_firestar.sql +23 -0
  7. package/dist/migrations/meta/0003_snapshot.json +422 -0
  8. package/dist/migrations/meta/0004_snapshot.json +429 -0
  9. package/dist/migrations/meta/_journal.json +14 -0
  10. package/dist/src/constants.d.ts +4 -0
  11. package/dist/src/errors.d.ts +1 -1
  12. package/dist/src/extractor/relation-extractor.d.ts +2 -1
  13. package/dist/src/gildash/context.d.ts +91 -0
  14. package/dist/src/gildash/extract-api.d.ts +9 -0
  15. package/dist/src/gildash/graph-api.d.ts +30 -0
  16. package/dist/src/gildash/index.d.ts +92 -0
  17. package/dist/src/gildash/lifecycle.d.ts +62 -0
  18. package/dist/src/gildash/misc-api.d.ts +22 -0
  19. package/dist/src/gildash/parse-api.d.ts +11 -0
  20. package/dist/src/gildash/query-api.d.ts +35 -0
  21. package/dist/src/gildash/semantic-api.d.ts +22 -0
  22. package/dist/src/gildash/types.d.ts +160 -0
  23. package/dist/src/index.d.ts +2 -1
  24. package/dist/src/indexer/index-coordinator.d.ts +8 -2
  25. package/dist/src/indexer/relation-indexer.d.ts +6 -0
  26. package/dist/src/search/dependency-graph.d.ts +1 -0
  27. package/dist/src/search/relation-search.d.ts +11 -1
  28. package/dist/src/search/symbol-search.d.ts +6 -0
  29. package/dist/src/semantic/ast-node-utils.d.ts +9 -0
  30. package/dist/src/semantic/implementation-finder.d.ts +22 -0
  31. package/dist/src/semantic/index.d.ts +68 -0
  32. package/dist/src/semantic/reference-resolver.d.ts +19 -0
  33. package/dist/src/semantic/symbol-graph.d.ts +36 -0
  34. package/dist/src/semantic/tsc-program.d.ts +67 -0
  35. package/dist/src/semantic/type-collector.d.ts +27 -0
  36. package/dist/src/semantic/types.d.ts +103 -0
  37. package/dist/src/store/repositories/relation.repository.d.ts +14 -2
  38. package/dist/src/store/repositories/symbol.repository.d.ts +2 -0
  39. package/dist/src/store/schema.d.ts +38 -0
  40. package/package.json +3 -2
  41. package/dist/src/gildash.d.ts +0 -821
@@ -0,0 +1,92 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import type { ParsedFile } from '../parser/types';
3
+ import type { ParserOptions } from 'oxc-parser';
4
+ import type { ExtractedSymbol, CodeRelation } from '../extractor/types';
5
+ import type { IndexResult } from '../indexer/index-coordinator';
6
+ import type { ProjectBoundary } from '../common/project-discovery';
7
+ import type { SymbolSearchQuery, SymbolSearchResult } from '../search/symbol-search';
8
+ import type { RelationSearchQuery } from '../search/relation-search';
9
+ import type { SymbolStats } from '../store/repositories/symbol.repository';
10
+ import type { FileRecord } from '../store/repositories/file.repository';
11
+ import type { PatternMatch } from '../search/pattern-search';
12
+ import type { GildashError } from '../errors';
13
+ import type { ResolvedType, SemanticReference, Implementation, SemanticModuleInterface } from '../semantic/types';
14
+ import type { GildashContext } from './context';
15
+ import type { GildashOptions, SymbolDiff, ModuleInterface, HeritageNode, FullSymbol, FileStats, FanMetrics, ResolvedSymbol } from './types';
16
+ import type { GildashInternalOptions } from './lifecycle';
17
+ export type { Logger, GildashOptions, SymbolDiff, ModuleInterface, HeritageNode, FullSymbol, FileStats, FanMetrics, ResolvedSymbol, } from './types';
18
+ export type { GildashInternalOptions } from './lifecycle';
19
+ /**
20
+ * Main entry point for gildash.
21
+ *
22
+ * `Gildash` indexes TypeScript source code into a local SQLite database,
23
+ * watches for file changes, and provides search / dependency-graph queries.
24
+ *
25
+ * Every public method returns a `Result<T, GildashError>` — either the
26
+ * success value `T` directly, or an `Err<GildashError>` that can be checked
27
+ * with `isErr()` from `@zipbul/result`.
28
+ *
29
+ * Create an instance with the static {@link Gildash.open} factory.
30
+ * Always call {@link Gildash.close} when done to release resources.
31
+ */
32
+ export declare class Gildash {
33
+ /** Internal state — exposed for advanced testing only. */
34
+ readonly _ctx: GildashContext;
35
+ /** Absolute path to the indexed project root. */
36
+ get projectRoot(): string;
37
+ /** Current watcher role: `'owner'` (can reindex) or `'reader'` (read-only). */
38
+ get role(): 'owner' | 'reader';
39
+ /** Discovered project boundaries within the project root. */
40
+ get projects(): ProjectBoundary[];
41
+ private constructor();
42
+ /**
43
+ * Create and initialise a new `Gildash` instance.
44
+ */
45
+ static open(options: GildashOptions & GildashInternalOptions): Promise<Result<Gildash, GildashError>>;
46
+ /** Shut down the instance and release all resources. */
47
+ close(opts?: {
48
+ cleanup?: boolean;
49
+ }): Promise<Result<void, GildashError>>;
50
+ parseSource(filePath: string, sourceText: string, options?: ParserOptions): Result<ParsedFile, GildashError>;
51
+ batchParse(filePaths: string[], options?: ParserOptions): Promise<Result<Map<string, ParsedFile>, GildashError>>;
52
+ getParsedAst(filePath: string): ParsedFile | undefined;
53
+ extractSymbols(parsed: ParsedFile): Result<ExtractedSymbol[], GildashError>;
54
+ extractRelations(parsed: ParsedFile): Result<CodeRelation[], GildashError>;
55
+ getStats(project?: string): Result<SymbolStats, GildashError>;
56
+ searchSymbols(query: SymbolSearchQuery): Result<SymbolSearchResult[], GildashError>;
57
+ searchRelations(query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
58
+ searchAllSymbols(query: Omit<SymbolSearchQuery, 'project'> & {
59
+ project?: string;
60
+ }): Result<SymbolSearchResult[], GildashError>;
61
+ searchAllRelations(query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
62
+ listIndexedFiles(project?: string): Result<FileRecord[], GildashError>;
63
+ getInternalRelations(filePath: string, project?: string): Result<CodeRelation[], GildashError>;
64
+ getFullSymbol(symbolName: string, filePath: string, project?: string): Result<FullSymbol, GildashError>;
65
+ getFileStats(filePath: string, project?: string): Result<FileStats, GildashError>;
66
+ getFileInfo(filePath: string, project?: string): Result<FileRecord | null, GildashError>;
67
+ getSymbolsByFile(filePath: string, project?: string): Result<SymbolSearchResult[], GildashError>;
68
+ getModuleInterface(filePath: string, project?: string): Result<ModuleInterface, GildashError>;
69
+ getDependencies(filePath: string, project?: string, limit?: number): Result<string[], GildashError>;
70
+ getDependents(filePath: string, project?: string, limit?: number): Result<string[], GildashError>;
71
+ getAffected(changedFiles: string[], project?: string): Promise<Result<string[], GildashError>>;
72
+ hasCycle(project?: string): Promise<Result<boolean, GildashError>>;
73
+ getImportGraph(project?: string): Promise<Result<Map<string, string[]>, GildashError>>;
74
+ getTransitiveDependencies(filePath: string, project?: string): Promise<Result<string[], GildashError>>;
75
+ getCyclePaths(project?: string, options?: {
76
+ maxCycles?: number;
77
+ }): Promise<Result<string[][], GildashError>>;
78
+ getFanMetrics(filePath: string, project?: string): Promise<Result<FanMetrics, GildashError>>;
79
+ getResolvedType(symbolName: string, filePath: string, project?: string): Result<ResolvedType | null, GildashError>;
80
+ getSemanticReferences(symbolName: string, filePath: string, project?: string): Result<SemanticReference[], GildashError>;
81
+ getImplementations(symbolName: string, filePath: string, project?: string): Result<Implementation[], GildashError>;
82
+ getSemanticModuleInterface(filePath: string): Result<SemanticModuleInterface, GildashError>;
83
+ diffSymbols(before: SymbolSearchResult[], after: SymbolSearchResult[]): SymbolDiff;
84
+ onIndexed(callback: (result: IndexResult) => void): () => void;
85
+ reindex(): Promise<Result<IndexResult, GildashError>>;
86
+ resolveSymbol(symbolName: string, filePath: string, project?: string): Result<ResolvedSymbol, GildashError>;
87
+ findPattern(pattern: string, opts?: {
88
+ filePaths?: string[];
89
+ project?: string;
90
+ }): Promise<Result<PatternMatch[], GildashError>>;
91
+ getHeritageChain(symbolName: string, filePath: string, project?: string): Promise<Result<HeritageNode, GildashError>>;
92
+ }
@@ -0,0 +1,62 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import { FileRepository } from '../store/repositories/file.repository';
3
+ import { SymbolRepository } from '../store/repositories/symbol.repository';
4
+ import { RelationRepository } from '../store/repositories/relation.repository';
5
+ import { acquireWatcherRole, releaseWatcherRole, updateHeartbeat } from '../watcher/ownership';
6
+ import { discoverProjects } from '../common/project-discovery';
7
+ import { loadTsconfigPaths } from '../common/tsconfig-resolver';
8
+ import { ParseCache } from '../parser/parse-cache';
9
+ import { parseSource as defaultParseSource } from '../parser/parse-source';
10
+ import { extractSymbols as defaultExtractSymbols } from '../extractor/symbol-extractor';
11
+ import { extractRelations as defaultExtractRelations } from '../extractor/relation-extractor';
12
+ import { symbolSearch as defaultSymbolSearch } from '../search/symbol-search';
13
+ import { relationSearch as defaultRelationSearch } from '../search/relation-search';
14
+ import type { PatternMatch } from '../search/pattern-search';
15
+ import { SemanticLayer } from '../semantic/index';
16
+ import type { GildashError } from '../errors';
17
+ import type { GildashContext, CoordinatorLike, WatcherLike, DbStore } from './context';
18
+ import type { GildashOptions } from './types';
19
+ export declare const HEARTBEAT_INTERVAL_MS = 30000;
20
+ export declare const HEALTHCHECK_INTERVAL_MS = 60000;
21
+ export declare const MAX_HEALTHCHECK_RETRIES = 10;
22
+ export interface GildashInternalOptions {
23
+ existsSyncFn?: (p: string) => boolean;
24
+ dbConnectionFactory?: () => DbStore;
25
+ watcherFactory?: () => WatcherLike;
26
+ coordinatorFactory?: () => CoordinatorLike;
27
+ repositoryFactory?: () => {
28
+ fileRepo: Pick<FileRepository, 'upsertFile' | 'getAllFiles' | 'getFilesMap' | 'deleteFile' | 'getFile'>;
29
+ symbolRepo: SymbolRepository;
30
+ relationRepo: RelationRepository;
31
+ parseCache: Pick<ParseCache, 'set' | 'get' | 'invalidate'>;
32
+ };
33
+ acquireWatcherRoleFn?: typeof acquireWatcherRole;
34
+ releaseWatcherRoleFn?: typeof releaseWatcherRole;
35
+ updateHeartbeatFn?: typeof updateHeartbeat;
36
+ discoverProjectsFn?: typeof discoverProjects;
37
+ parseSourceFn?: typeof defaultParseSource;
38
+ extractSymbolsFn?: typeof defaultExtractSymbols;
39
+ extractRelationsFn?: typeof defaultExtractRelations;
40
+ symbolSearchFn?: typeof defaultSymbolSearch;
41
+ relationSearchFn?: typeof defaultRelationSearch;
42
+ patternSearchFn?: (opts: {
43
+ pattern: string;
44
+ filePaths: string[];
45
+ }) => Promise<PatternMatch[]>;
46
+ loadTsconfigPathsFn?: typeof loadTsconfigPaths;
47
+ readFileFn?: (filePath: string) => Promise<string>;
48
+ unlinkFn?: (filePath: string) => Promise<void>;
49
+ semanticLayerFactory?: (tsconfigPath: string) => Result<SemanticLayer, GildashError>;
50
+ }
51
+ /** Create coordinator + watcher, start watcher, heartbeat timer, run fullIndex. */
52
+ export declare function setupOwnerInfrastructure(ctx: GildashContext, opts: {
53
+ isWatchMode: boolean;
54
+ }): Promise<void>;
55
+ /** Register SIGTERM / SIGINT / beforeExit handlers. */
56
+ export declare function registerSignalHandlers(ctx: GildashContext, closeFn: () => Promise<Result<void, GildashError> | undefined>): void;
57
+ /** Initialize a GildashContext (replaces the old `Gildash.open()` body). */
58
+ export declare function initializeContext(options: GildashOptions & GildashInternalOptions): Promise<Result<GildashContext, GildashError>>;
59
+ /** Shut down the context and release all resources. */
60
+ export declare function closeContext(ctx: GildashContext, opts?: {
61
+ cleanup?: boolean;
62
+ }): Promise<Result<void, GildashError>>;
@@ -0,0 +1,22 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import type { SymbolSearchResult } from '../search/symbol-search';
3
+ import type { IndexResult } from '../indexer/index-coordinator';
4
+ import type { PatternMatch } from '../search/pattern-search';
5
+ import type { GildashError } from '../errors';
6
+ import type { GildashContext } from './context';
7
+ import type { SymbolDiff, ResolvedSymbol, HeritageNode } from './types';
8
+ /** Compare two snapshots of symbol search results and return a structured diff. */
9
+ export declare function diffSymbols(before: SymbolSearchResult[], after: SymbolSearchResult[]): SymbolDiff;
10
+ /** Register a callback that fires after each indexing run completes. */
11
+ export declare function onIndexed(ctx: GildashContext, callback: (result: IndexResult) => void): () => void;
12
+ /** Trigger a full re-index of all tracked files. */
13
+ export declare function reindex(ctx: GildashContext): Promise<Result<IndexResult, GildashError>>;
14
+ /** Resolve the original definition location of a symbol by following its re-export chain. */
15
+ export declare function resolveSymbol(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Result<ResolvedSymbol, GildashError>;
16
+ /** Search for an AST structural pattern across indexed TypeScript files. */
17
+ export declare function findPattern(ctx: GildashContext, pattern: string, opts?: {
18
+ filePaths?: string[];
19
+ project?: string;
20
+ }): Promise<Result<PatternMatch[], GildashError>>;
21
+ /** Recursively traverse extends/implements relations to build a heritage tree. */
22
+ export declare function getHeritageChain(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Promise<Result<HeritageNode, GildashError>>;
@@ -0,0 +1,11 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import type { ParsedFile } from '../parser/types';
3
+ import type { ParserOptions } from 'oxc-parser';
4
+ import type { GildashError } from '../errors';
5
+ import type { GildashContext } from './context';
6
+ /** Parse a TypeScript source string into an AST and cache the result. */
7
+ export declare function parseSource(ctx: GildashContext, filePath: string, sourceText: string, options?: ParserOptions): Result<ParsedFile, GildashError>;
8
+ /** Parse multiple files concurrently and return a map of results. */
9
+ export declare function batchParse(ctx: GildashContext, filePaths: string[], options?: ParserOptions): Promise<Result<Map<string, ParsedFile>, GildashError>>;
10
+ /** Retrieve a previously-parsed AST from the internal LRU cache. */
11
+ export declare function getParsedAst(ctx: GildashContext, filePath: string): ParsedFile | undefined;
@@ -0,0 +1,35 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import type { SymbolSearchQuery, SymbolSearchResult } from '../search/symbol-search';
3
+ import type { RelationSearchQuery } from '../search/relation-search';
4
+ import type { CodeRelation } from '../extractor/types';
5
+ import type { FileRecord } from '../store/repositories/file.repository';
6
+ import type { SymbolStats } from '../store/repositories/symbol.repository';
7
+ import type { GildashError } from '../errors';
8
+ import type { GildashContext } from './context';
9
+ import type { FullSymbol, FileStats, ModuleInterface } from './types';
10
+ /** Return aggregate symbol statistics for the given project. */
11
+ export declare function getStats(ctx: GildashContext, project?: string): Result<SymbolStats, GildashError>;
12
+ /** Search indexed symbols by name, kind, file path, or export status. */
13
+ export declare function searchSymbols(ctx: GildashContext, query: SymbolSearchQuery): Result<SymbolSearchResult[], GildashError>;
14
+ /** Search indexed code relationships (imports, calls, extends, implements). */
15
+ export declare function searchRelations(ctx: GildashContext, query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
16
+ /** Search symbols across all projects (no project filter). */
17
+ export declare function searchAllSymbols(ctx: GildashContext, query: Omit<SymbolSearchQuery, 'project'> & {
18
+ project?: string;
19
+ }): Result<SymbolSearchResult[], GildashError>;
20
+ /** Search relations across all projects (no project filter). */
21
+ export declare function searchAllRelations(ctx: GildashContext, query: RelationSearchQuery): Result<CodeRelation[], GildashError>;
22
+ /** List all files indexed for a given project. */
23
+ export declare function listIndexedFiles(ctx: GildashContext, project?: string): Result<FileRecord[], GildashError>;
24
+ /** Get all intra-file relations for a given file. */
25
+ export declare function getInternalRelations(ctx: GildashContext, filePath: string, project?: string): Result<CodeRelation[], GildashError>;
26
+ /** Retrieve full details for a named symbol in a specific file. */
27
+ export declare function getFullSymbol(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Result<FullSymbol, GildashError>;
28
+ /** Retrieve statistics for an indexed file. */
29
+ export declare function getFileStats(ctx: GildashContext, filePath: string, project?: string): Result<FileStats, GildashError>;
30
+ /** Retrieve metadata for an indexed file. */
31
+ export declare function getFileInfo(ctx: GildashContext, filePath: string, project?: string): Result<FileRecord | null, GildashError>;
32
+ /** List all symbols declared in a specific file. */
33
+ export declare function getSymbolsByFile(ctx: GildashContext, filePath: string, project?: string): Result<SymbolSearchResult[], GildashError>;
34
+ /** Return the public interface of a module. */
35
+ export declare function getModuleInterface(ctx: GildashContext, filePath: string, project?: string): Result<ModuleInterface, GildashError>;
@@ -0,0 +1,22 @@
1
+ import { type Result } from '@zipbul/result';
2
+ import type { SymbolSearchResult } from '../search/symbol-search';
3
+ import type { GildashError } from '../errors';
4
+ import type { ResolvedType, SemanticReference, Implementation, SemanticModuleInterface } from '../semantic/types';
5
+ import type { GildashContext } from './context';
6
+ /**
7
+ * Look up a symbol's position for semantic queries.
8
+ * Returns `null` when the symbol is not indexed or position cannot be resolved.
9
+ */
10
+ export declare function resolveSymbolPosition(ctx: GildashContext, symbolName: string, filePath: string, project?: string): {
11
+ sym: SymbolSearchResult;
12
+ position: number;
13
+ absPath: string;
14
+ } | null;
15
+ /** Retrieve the resolved type of a symbol using the Semantic Layer. */
16
+ export declare function getResolvedType(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Result<ResolvedType | null, GildashError>;
17
+ /** Find all semantic references to a symbol. */
18
+ export declare function getSemanticReferences(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Result<SemanticReference[], GildashError>;
19
+ /** Find implementations of an interface/abstract class. */
20
+ export declare function getImplementations(ctx: GildashContext, symbolName: string, filePath: string, project?: string): Result<Implementation[], GildashError>;
21
+ /** Retrieve the semantic module interface — exported symbols with resolved types. */
22
+ export declare function getSemanticModuleInterface(ctx: GildashContext, filePath: string): Result<SemanticModuleInterface, GildashError>;
@@ -0,0 +1,160 @@
1
+ import type { SymbolSearchResult } from '../search/symbol-search';
2
+ import type { SymbolKind } from '../extractor/types';
3
+ import type { ResolvedType } from '../semantic/types';
4
+ /**
5
+ * Minimal logger interface accepted by {@link Gildash}.
6
+ *
7
+ * Any object with an `error` method (including `console`) satisfies this interface.
8
+ */
9
+ export interface Logger {
10
+ /** Log one or more error-level messages. */
11
+ error(...args: unknown[]): void;
12
+ }
13
+ /**
14
+ * Result of a {@link Gildash.diffSymbols} call.
15
+ */
16
+ export interface SymbolDiff {
17
+ /** Symbols present in `after` but not in `before`. */
18
+ added: SymbolSearchResult[];
19
+ /** Symbols present in `before` but not in `after`. */
20
+ removed: SymbolSearchResult[];
21
+ /** Symbols present in both but with a different `fingerprint`. */
22
+ modified: Array<{
23
+ before: SymbolSearchResult;
24
+ after: SymbolSearchResult;
25
+ }>;
26
+ }
27
+ /**
28
+ * Public interface of a module — its exported symbols with key metadata.
29
+ * Returned by {@link Gildash.getModuleInterface}.
30
+ */
31
+ export interface ModuleInterface {
32
+ filePath: string;
33
+ exports: Array<{
34
+ name: string;
35
+ kind: SymbolKind;
36
+ parameters?: string;
37
+ returnType?: string;
38
+ jsDoc?: string;
39
+ }>;
40
+ }
41
+ /**
42
+ * A node in the heritage chain tree returned by {@link Gildash.getHeritageChain}.
43
+ */
44
+ export interface HeritageNode {
45
+ symbolName: string;
46
+ filePath: string;
47
+ /** Relationship kind (`extends` or `implements`). Undefined for the root query node. */
48
+ kind?: 'extends' | 'implements';
49
+ children: HeritageNode[];
50
+ }
51
+ /**
52
+ * Full symbol detail including members, documentation, and type information.
53
+ * Returned by {@link Gildash.getFullSymbol}.
54
+ */
55
+ export interface FullSymbol extends SymbolSearchResult {
56
+ /** Class/interface members (methods, properties, constructors, accessors). */
57
+ members?: Array<{
58
+ name: string;
59
+ kind: string;
60
+ type?: string;
61
+ visibility?: string;
62
+ isStatic?: boolean;
63
+ isReadonly?: boolean;
64
+ }>;
65
+ /** JSDoc comment attached to the symbol. */
66
+ jsDoc?: string;
67
+ /** Stringified parameter list (functions/methods). */
68
+ parameters?: string;
69
+ /** Stringified return type (functions/methods). */
70
+ returnType?: string;
71
+ /** Superclass/interface names (classes/interfaces with heritage). */
72
+ heritage?: string[];
73
+ /** Decorators applied to the symbol. */
74
+ decorators?: Array<{
75
+ name: string;
76
+ arguments?: string;
77
+ }>;
78
+ /** Stringified type parameters (generic symbols). */
79
+ typeParameters?: string;
80
+ /** Resolved type from the Semantic Layer (available when `semantic: true`). */
81
+ resolvedType?: ResolvedType;
82
+ }
83
+ /**
84
+ * File-level statistics for an indexed file.
85
+ * Returned by {@link Gildash.getFileStats}.
86
+ */
87
+ export interface FileStats {
88
+ /** Absolute file path. */
89
+ filePath: string;
90
+ /** Number of lines in the file at the time of last indexing. */
91
+ lineCount: number;
92
+ /** Number of symbols indexed in the file. */
93
+ symbolCount: number;
94
+ /** Number of outgoing relations (imports, calls, etc.) from the file. */
95
+ relationCount: number;
96
+ /** File size in bytes at the time of last indexing. */
97
+ size: number;
98
+ /** Number of exported symbols in the file. */
99
+ exportedSymbolCount: number;
100
+ }
101
+ /**
102
+ * Import-graph fan metrics for a single file.
103
+ * Returned by {@link Gildash.getFanMetrics}.
104
+ */
105
+ export interface FanMetrics {
106
+ /** Absolute file path queried. */
107
+ filePath: string;
108
+ /** Number of files that import this file (fan-in). */
109
+ fanIn: number;
110
+ /** Number of files this file imports (fan-out). */
111
+ fanOut: number;
112
+ }
113
+ /**
114
+ * Result of following a re-export chain to the original symbol definition.
115
+ */
116
+ export interface ResolvedSymbol {
117
+ /** The name of the symbol at the end of the re-export chain (may differ from the queried name due to aliasing). */
118
+ originalName: string;
119
+ /** Absolute path of the file that originally defines the symbol. */
120
+ originalFilePath: string;
121
+ /** Ordered list of re-export hops between the queried file and the original definition. */
122
+ reExportChain: Array<{
123
+ filePath: string;
124
+ exportedAs: string;
125
+ }>;
126
+ }
127
+ /**
128
+ * Options for creating a {@link Gildash} instance via {@link Gildash.open}.
129
+ */
130
+ export interface GildashOptions {
131
+ /** Absolute path to the project root directory. */
132
+ projectRoot: string;
133
+ /** File extensions to index. Defaults to `['.ts', '.mts', '.cts']`. */
134
+ extensions?: string[];
135
+ /** Glob patterns to ignore during indexing. */
136
+ ignorePatterns?: string[];
137
+ /** Maximum number of parsed ASTs to keep in the LRU cache. Defaults to `500`. */
138
+ parseCacheCapacity?: number;
139
+ /** Logger for error output. Defaults to `console`. */
140
+ logger?: Logger;
141
+ /**
142
+ * When `false`, disables the file watcher and runs in scan-only mode:
143
+ * ownership contention is skipped, heartbeat and signal handlers are not
144
+ * registered, and only the initial `fullIndex()` is performed.
145
+ *
146
+ * Set `cleanup: true` in {@link Gildash.close} to remove the database files
147
+ * after a one-shot scan.
148
+ *
149
+ * @default true
150
+ */
151
+ watchMode?: boolean;
152
+ /**
153
+ * Enable the Semantic Layer (tsc-based type analysis).
154
+ * When `true`, creates a `SemanticLayer` backed by the TypeScript compiler.
155
+ * Requires a `tsconfig.json` in `projectRoot`.
156
+ *
157
+ * @default false
158
+ */
159
+ semantic?: boolean;
160
+ }
@@ -5,7 +5,7 @@ export type { GildashError, GildashErrorType } from "./errors";
5
5
  export { symbolSearch } from "./search/symbol-search";
6
6
  export type { SymbolSearchQuery, SymbolSearchResult } from "./search/symbol-search";
7
7
  export { relationSearch } from "./search/relation-search";
8
- export type { RelationSearchQuery } from "./search/relation-search";
8
+ export type { RelationSearchQuery, StoredCodeRelation } from "./search/relation-search";
9
9
  export { DependencyGraph } from "./search/dependency-graph";
10
10
  export { patternSearch } from "./search/pattern-search";
11
11
  export type { PatternMatch, PatternSearchOptions } from "./search/pattern-search";
@@ -16,3 +16,4 @@ export type { SymbolStats } from "./store/repositories/symbol.repository";
16
16
  export type { WatcherRole } from "./watcher/types";
17
17
  export type { ParsedFile } from "./parser/types";
18
18
  export type { FileRecord } from "./store/repositories/file.repository";
19
+ export type { ResolvedType, SemanticReference, Implementation, SemanticModuleInterface } from "./semantic/types";
@@ -80,7 +80,14 @@ export interface IndexCoordinatorOptions {
80
80
  };
81
81
  relationRepo: {
82
82
  replaceFileRelations(project: string, filePath: string, relations: ReadonlyArray<Partial<RelationRecord>>): void;
83
- retargetRelations(project: string, oldFile: string, oldSymbol: string | null, newFile: string, newSymbol: string | null): void;
83
+ retargetRelations(opts: {
84
+ dstProject: string;
85
+ oldFile: string;
86
+ oldSymbol: string | null;
87
+ newFile: string;
88
+ newSymbol: string | null;
89
+ newDstProject?: string;
90
+ }): void;
84
91
  deleteFileRelations(project: string, filePath: string): void;
85
92
  };
86
93
  parseSourceFn?: typeof parseSource;
@@ -108,7 +115,6 @@ export declare class IndexCoordinator {
108
115
  shutdown(): Promise<void>;
109
116
  private startIndex;
110
117
  private doIndex;
111
- private processFile;
112
118
  private fireCallbacks;
113
119
  private flushPending;
114
120
  }
@@ -1,10 +1,12 @@
1
1
  import type { Program } from 'oxc-parser';
2
+ import type { ProjectBoundary } from '../common/project-discovery';
2
3
  import type { TsconfigPaths } from '../common/tsconfig-resolver';
3
4
  export interface RelationDbRow {
4
5
  project: string;
5
6
  type: string;
6
7
  srcFilePath: string;
7
8
  srcSymbolName: string | null;
9
+ dstProject: string;
8
10
  dstFilePath: string;
9
11
  dstSymbolName: string | null;
10
12
  metaJson: string | null;
@@ -19,6 +21,10 @@ export interface IndexFileRelationsOptions {
19
21
  relationRepo: RelationRepoPart;
20
22
  projectRoot: string;
21
23
  tsconfigPaths?: TsconfigPaths;
24
+ /** 인덱싱된 파일 경로 Set. `${project}::${filePath}` 형식. */
25
+ knownFiles?: Set<string>;
26
+ /** 프로젝트 경계 목록 (dstProject 결정용) */
27
+ boundaries?: ProjectBoundary[];
22
28
  }
23
29
  export declare function indexFileRelations(opts: IndexFileRelationsOptions): number;
24
30
  export {};
@@ -24,6 +24,7 @@ export declare class DependencyGraph {
24
24
  constructor(options: {
25
25
  relationRepo: IDependencyGraphRepo;
26
26
  project: string;
27
+ additionalProjects?: string[];
27
28
  });
28
29
  /**
29
30
  * Populate the graph by reading all `imports` relations from the store.
@@ -1,5 +1,12 @@
1
1
  import type { CodeRelation } from '../extractor/types';
2
2
  import type { RelationRecord } from '../store/repositories/relation.repository';
3
+ /**
4
+ * A {@link CodeRelation} enriched with the destination project identifier
5
+ * as stored in the relation index.
6
+ */
7
+ export interface StoredCodeRelation extends CodeRelation {
8
+ dstProject: string;
9
+ }
3
10
  /**
4
11
  * Filters for {@link relationSearch}.
5
12
  *
@@ -14,6 +21,8 @@ export interface RelationSearchQuery {
14
21
  dstFilePath?: string;
15
22
  /** Destination symbol name. */
16
23
  dstSymbolName?: string;
24
+ /** Destination project. */
25
+ dstProject?: string;
17
26
  /** Relationship type: `'imports'`, `'calls'`, `'extends'`, or `'implements'`. */
18
27
  type?: CodeRelation['type'];
19
28
  /** Limit results to this project. */
@@ -27,6 +36,7 @@ export interface IRelationRepo {
27
36
  srcSymbolName?: string;
28
37
  dstFilePath?: string;
29
38
  dstSymbolName?: string;
39
+ dstProject?: string;
30
40
  type?: string;
31
41
  project?: string;
32
42
  limit: number;
@@ -42,4 +52,4 @@ export declare function relationSearch(options: {
42
52
  relationRepo: IRelationRepo;
43
53
  project?: string;
44
54
  query: RelationSearchQuery;
45
- }): CodeRelation[];
55
+ }): StoredCodeRelation[];
@@ -30,6 +30,11 @@ export interface SymbolSearchQuery {
30
30
  * Requires the `REGEXP` SQL function to be registered in the DB connection.
31
31
  */
32
32
  regex?: string;
33
+ /**
34
+ * Filter by the resolved (inferred) type text.
35
+ * Requires the semantic layer (`semantic: true`) to have populated this field.
36
+ */
37
+ resolvedType?: string;
33
38
  }
34
39
  /**
35
40
  * A single result returned by {@link symbolSearch}.
@@ -74,6 +79,7 @@ export interface ISymbolRepo {
74
79
  limit: number;
75
80
  decorator?: string;
76
81
  regex?: string;
82
+ resolvedType?: string;
77
83
  }): (SymbolRecord & {
78
84
  id: number;
79
85
  })[];
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Shared AST node utilities for the semantic layer.
3
+ */
4
+ import ts from "typescript";
5
+ /**
6
+ * `pos` 위치의 가장 작은(innermost) 노드를 반환한다.
7
+ * 범위 밖이면 `undefined`.
8
+ */
9
+ export declare function findNodeAtPosition(sourceFile: ts.SourceFile, pos: number): ts.Node | undefined;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * ImplementationFinder — findImplementations + isTypeAssignableTo 기반 구현체 탐색.
3
+ *
4
+ * interface/abstract class의 구현체를 찾는다.
5
+ * - LanguageService.getImplementationAtPosition: 명시적 + 일부 구조적 구현체
6
+ * - TypeChecker.isTypeAssignableTo: 덕 타이핑 구현체 검증
7
+ *
8
+ * 명시적(`implements` 키워드) 구현과 구조적(duck-typing) 구현 모두 탐지한다.
9
+ */
10
+ import type { Implementation } from "./types";
11
+ import type { TscProgram } from "./tsc-program";
12
+ export declare class ImplementationFinder {
13
+ #private;
14
+ constructor(program: TscProgram);
15
+ /**
16
+ * `filePath`의 `position` 위치 심볼에 대한 구현체를 찾는다.
17
+ *
18
+ * - 프로그램이 dispose되었거나 심볼을 찾을 수 없으면 빈 배열을 반환한다.
19
+ * - 명시적 `implements` + 구조적 타이핑(duck-typing) 구현체 모두 포함한다.
20
+ */
21
+ findAt(filePath: string, position: number): Implementation[];
22
+ }
@@ -0,0 +1,68 @@
1
+ /**
2
+ * SemanticLayer — tsc 기반 시맨틱 분석 계층.
3
+ *
4
+ * TscProgram + TypeCollector + SymbolGraph + ReferenceResolver + ImplementationFinder를
5
+ * 하나의 facade로 통합한다.
6
+ */
7
+ import { type Result } from "@zipbul/result";
8
+ import { type GildashError } from "../errors";
9
+ import { type TscProgramOptions } from "./tsc-program";
10
+ import { TypeCollector } from "./type-collector";
11
+ import { SymbolGraph, type SymbolNode } from "./symbol-graph";
12
+ import { ReferenceResolver } from "./reference-resolver";
13
+ import { ImplementationFinder } from "./implementation-finder";
14
+ import type { ResolvedType, SemanticReference, Implementation, SemanticModuleInterface } from "./types";
15
+ export interface SemanticLayerOptions extends TscProgramOptions {
16
+ /** Override TypeCollector (for testing). */
17
+ typeCollector?: TypeCollector;
18
+ /** Override SymbolGraph (for testing). */
19
+ symbolGraph?: SymbolGraph;
20
+ /** Override ReferenceResolver (for testing). */
21
+ referenceResolver?: ReferenceResolver;
22
+ /** Override ImplementationFinder (for testing). */
23
+ implementationFinder?: ImplementationFinder;
24
+ }
25
+ export declare class SemanticLayer {
26
+ #private;
27
+ private constructor();
28
+ /**
29
+ * Create a SemanticLayer from a tsconfig.json path.
30
+ *
31
+ * Internally creates TscProgram and all sub-modules.
32
+ * DI overrides via `options` for testing.
33
+ */
34
+ static create(tsconfigPath: string, options?: SemanticLayerOptions): Result<SemanticLayer, GildashError>;
35
+ get isDisposed(): boolean;
36
+ collectTypeAt(filePath: string, position: number): ResolvedType | null;
37
+ collectFileTypes(filePath: string): Map<number, ResolvedType>;
38
+ findReferences(filePath: string, position: number): SemanticReference[];
39
+ findImplementations(filePath: string, position: number): Implementation[];
40
+ getSymbolNode(filePath: string, position: number): SymbolNode | null;
41
+ getModuleInterface(filePath: string): SemanticModuleInterface;
42
+ notifyFileChanged(filePath: string, content: string): void;
43
+ /**
44
+ * Remove a tracked file from the tsc program and invalidate its symbol graph entries.
45
+ *
46
+ * Call this when a file is deleted from disk so the LanguageService no longer
47
+ * reports stale references or type information for it.
48
+ *
49
+ * No-op if already disposed.
50
+ */
51
+ notifyFileDeleted(filePath: string): void;
52
+ /**
53
+ * Convert 1-based line + 0-based column to a byte offset using tsc SourceFile.
54
+ * Returns `null` when the file is not part of the program.
55
+ */
56
+ lineColumnToPosition(filePath: string, line: number, column: number): number | null;
57
+ /**
58
+ * Find the byte offset of a symbol **name** starting from its declaration position.
59
+ *
60
+ * `declarationPos` typically points to the `export` keyword (the declaration start
61
+ * stored in the DB), while the symbol name sits a few tokens ahead.
62
+ * Uses a simple text search to locate the first occurrence of `name` after `declarationPos`.
63
+ *
64
+ * Returns `null` when the file is not in the program or the name is not found.
65
+ */
66
+ findNamePosition(filePath: string, declarationPos: number, name: string): number | null;
67
+ dispose(): void;
68
+ }