import type { Definition } from '../parser/definition-extractor.js'; import type { FileReference, ImportedSymbol, SymbolUsage } from '../parser/reference-extractor.js'; export interface FileInsert { path: string; language: string; contentHash: string; sizeBytes: number; modifiedAt: string; } export interface CallsiteResult { usageId: number; symbolId: number; definitionId: number | null; filePath: string; line: number; column: number; symbolName: string; localName: string; argumentCount: number; isMethodCall: boolean; isConstructorCall: boolean; receiverName: string | null; } export interface DependencyInfo { dependencyId: number; name: string; kind: string; filePath: string; line: number; } export interface ReadySymbolInfo { id: number; name: string; kind: string; filePath: string; line: number; endLine: number; dependencyCount: number; } export interface DependencyWithMetadata { id: number; name: string; kind: string; filePath: string; line: number; hasAspect: boolean; aspectValue: string | null; } export interface IncomingDependency { id: number; name: string; kind: string; filePath: string; line: number; } export type RelationshipType = 'uses' | 'extends' | 'implements'; export interface RelationshipAnnotation { id: number; fromDefinitionId: number; toDefinitionId: number; relationshipType: RelationshipType; semantic: string; createdAt: string; } export interface RelationshipWithDetails { id: number; fromDefinitionId: number; fromName: string; fromKind: string; fromFilePath: string; fromLine: number; toDefinitionId: number; toName: string; toKind: string; toFilePath: string; toLine: number; relationshipType: RelationshipType; semantic: string; } export interface Domain { id: number; name: string; description: string | null; createdAt: string; } export interface DomainWithCount extends Domain { symbolCount: number; } export interface Contract { id: number; protocol: string; key: string; normalizedKey: string; description: string | null; createdAt: string; } export interface ContractParticipant { id: number; contractId: number; definitionId: number; moduleId: number | null; role: string; } export interface ContractWithParticipants extends Contract { participants: ContractParticipant[]; } export interface InteractionDefinitionLink { interactionId: number; fromDefinitionId: number; toDefinitionId: number; contractId: number; } export interface Module { id: number; parentId: number | null; slug: string; fullPath: string; name: string; description: string | null; depth: number; colorIndex: number; isTest: boolean; createdAt: string; } export interface ModuleMember { moduleId: number; definitionId: number; assignedAt: string; } export interface ModuleTreeNode extends Module { children: ModuleTreeNode[]; } export interface ModuleWithMembers extends Module { members: Array<{ definitionId: number; name: string; kind: string; filePath: string; line: number; isExported: boolean; }>; } export interface CallGraphEdge { fromId: number; toId: number; weight: number; minUsageLine: number; } /** * Interaction source type: how the interaction was detected. */ export type InteractionSource = 'ast' | 'ast-import' | 'llm-inferred' | 'contract-matched'; /** * Interaction: Point-to-point module connection. * * Represents a uni- or bi-directional relationship between two modules, * with details about which symbols are called and the pattern of usage. */ export interface Interaction { id: number; fromModuleId: number; toModuleId: number; direction: 'uni' | 'bi'; weight: number; pattern: 'utility' | 'business' | 'test-internal' | null; symbols: string | null; semantic: string | null; source: InteractionSource; confidence: 'high' | 'medium' | null; createdAt: string; } /** * Enriched interaction with module path information for display */ export interface InteractionWithPaths extends Interaction { fromModulePath: string; toModulePath: string; } /** * Symbol detail within a module call edge */ export interface CalledSymbolInfo { name: string; kind: string; callCount: number; } /** * Module call graph edge for interaction detection */ export interface ModuleCallEdge { fromModuleId: number; toModuleId: number; weight: number; fromModulePath: string; toModulePath: string; } /** * Enriched module call edge with symbol-level details for better interaction detection */ export interface EnrichedModuleCallEdge extends ModuleCallEdge { calledSymbols: CalledSymbolInfo[]; avgCallsPerSymbol: number; distinctCallers: number; isHighFrequency: boolean; edgePattern: 'utility' | 'business' | 'test-internal'; minUsageLine: number; } export type DirtyLayer = 'metadata' | 'relationships' | 'modules' | 'contracts' | 'interactions' | 'flows' | 'features'; export type DirtyReason = 'added' | 'modified' | 'removed' | 'dependency_changed' | 'parent_dirty'; export interface SyncDirtyEntry { layer: DirtyLayer; entityId: number; reason: DirtyReason; } /** * Stakeholder types for flows */ export type FlowStakeholder = 'user' | 'admin' | 'system' | 'developer' | 'external'; /** * Flow: A user journey - sequence of interactions triggered by an entry point. * * Represents a complete path from trigger to outcome, documenting how * a feature works end-to-end. */ export interface Flow { id: number; name: string; slug: string; entryPointModuleId: number | null; entryPointId: number | null; entryPath: string | null; stakeholder: FlowStakeholder | null; description: string | null; actionType: string | null; targetEntity: string | null; tier: number; createdAt: string; } /** * Subflow step: references a child flow within a composite flow */ export interface FlowSubflowStep { flowId: number; stepOrder: number; subflowId: number; } /** * Flow step: An ordered interaction within a flow (module-level) */ export interface FlowStep { flowId: number; stepOrder: number; interactionId: number; } /** * Flow definition step: An ordered definition-level call edge within a flow */ export interface FlowDefinitionStep { flowId: number; stepOrder: number; fromDefinitionId: number; toDefinitionId: number; } /** * Flow definition step with full details for display */ export interface FlowDefinitionStepWithDetails extends FlowDefinitionStep { fromDefinitionName: string; fromDefinitionKind: string; fromFilePath: string; fromLine: number; fromModuleId: number | null; fromModulePath: string | null; toDefinitionName: string; toDefinitionKind: string; toFilePath: string; toLine: number; toModuleId: number | null; toModulePath: string | null; semantic: string | null; } /** * Flow with its steps and interaction details for display (module-level) */ export interface FlowWithSteps extends Flow { steps: Array; } /** * Flow with its definition-level steps for display */ export interface FlowWithDefinitionSteps extends Flow { definitionSteps: FlowDefinitionStepWithDetails[]; } /** * Expanded flow showing flattened interactions in order */ export interface ExpandedFlow { flow: Flow; interactions: InteractionWithPaths[]; } /** * Flow coverage statistics */ export interface FlowCoverageStats { totalInteractions: number; coveredByFlows: number; percentage: number; } /** * Relationship to interaction coverage statistics */ export interface RelationshipInteractionCoverage { totalRelationships: number; crossModuleRelationships: number; relationshipsContributingToInteractions: number; sameModuleCount: number; orphanedCount: number; coveragePercent: number; } /** * Detailed breakdown of relationship coverage for diagnostics */ export interface RelationshipCoverageBreakdown { covered: number; sameModule: number; noCallEdge: number; orphaned: number; byType: { uses: number; extends: number; implements: number; }; } export interface Feature { id: number; name: string; slug: string; description: string | null; createdAt: string; } export interface FeatureWithFlows extends Feature { flows: Flow[]; } export interface AnnotatedSymbolInfo { id: number; name: string; kind: string; filePath: string; line: number; endLine: number; isExported: boolean; purpose: string | null; domain: string[] | null; role: string | null; extendsName: string | null; extendedByCount: number; } export interface AnnotatedEdgeInfo { fromId: number; toId: number; weight: number; semantic: string | null; } export interface EnhancedRelationshipContext { fromDefinitionId: number; fromName: string; fromKind: string; fromFilePath: string; fromLine: number; fromEndLine: number; toDefinitionId: number; toName: string; toKind: string; toFilePath: string; toLine: number; toEndLine: number; fromPurpose: string | null; fromDomains: string[] | null; fromRole: string | null; fromPure: boolean | null; toPurpose: string | null; toDomains: string[] | null; toRole: string | null; toPure: boolean | null; relationshipType: 'call' | 'import' | 'extends' | 'implements'; usageLine: number; otherFromRelationships: string[]; otherToRelationships: string[]; sharedDomains: string[]; } /** * Interface for database operations, enabling mocking in tests. */ export interface IIndexWriter { initialize(): void; setMetadata(key: string, value: string): void; insertFile(file: FileInsert): number; insertDefinition(fileId: number, def: Definition): number; insertReference(fromFileId: number, toFileId: number | null, ref: FileReference): number; insertSymbol(refId: number | null, defId: number | null, sym: ImportedSymbol, fileId?: number): number; insertUsage(symbolId: number, usage: SymbolUsage): void; getDefinitionByName(fileId: number, name: string): number | null; getDefinitionCount(): number; getReferenceCount(): number; getUsageCount(): number; getCallsites(definitionId: number): CallsiteResult[]; getCallsitesForFile(fileId: number): CallsiteResult[]; getCallsiteCount(): number; close(): void; } export declare const SCHEMA = "\n-- Metadata about the indexing run\nCREATE TABLE metadata (\n key TEXT PRIMARY KEY,\n value TEXT NOT NULL\n);\n\n-- Files indexed by this run\nCREATE TABLE files (\n id INTEGER PRIMARY KEY,\n path TEXT UNIQUE NOT NULL,\n language TEXT NOT NULL,\n content_hash TEXT NOT NULL,\n size_bytes INTEGER NOT NULL,\n modified_at TEXT NOT NULL\n);\n\n-- All definitions (functions, classes, variables, types) in each file\nCREATE TABLE definitions (\n id INTEGER PRIMARY KEY,\n file_id INTEGER NOT NULL,\n name TEXT NOT NULL,\n kind TEXT NOT NULL,\n is_exported INTEGER NOT NULL,\n is_default INTEGER NOT NULL,\n line INTEGER NOT NULL,\n column INTEGER NOT NULL,\n end_line INTEGER NOT NULL,\n end_column INTEGER NOT NULL,\n declaration_end_line INTEGER NOT NULL,\n declaration_end_column INTEGER NOT NULL,\n extends_name TEXT, -- Parent class name (for classes)\n implements_names TEXT, -- JSON array of interface names (for classes)\n extends_interfaces TEXT, -- JSON array of parent interfaces (for interfaces)\n FOREIGN KEY (file_id) REFERENCES files(id)\n);\n\n-- Import/export relationships between files\nCREATE TABLE imports (\n id INTEGER PRIMARY KEY,\n from_file_id INTEGER NOT NULL,\n to_file_id INTEGER,\n type TEXT NOT NULL,\n source TEXT NOT NULL,\n is_external INTEGER NOT NULL,\n is_type_only INTEGER NOT NULL,\n line INTEGER NOT NULL,\n column INTEGER NOT NULL,\n FOREIGN KEY (from_file_id) REFERENCES files(id),\n FOREIGN KEY (to_file_id) REFERENCES files(id)\n);\n\n-- Symbols imported in each reference (or internal symbols within a file)\nCREATE TABLE symbols (\n id INTEGER PRIMARY KEY,\n reference_id INTEGER, -- NULL for internal symbols\n file_id INTEGER, -- Set for internal symbols (same-file references)\n definition_id INTEGER,\n name TEXT NOT NULL,\n local_name TEXT NOT NULL,\n kind TEXT NOT NULL,\n FOREIGN KEY (reference_id) REFERENCES imports(id),\n FOREIGN KEY (file_id) REFERENCES files(id),\n FOREIGN KEY (definition_id) REFERENCES definitions(id)\n);\n\n-- Where each imported symbol is used in the file\nCREATE TABLE usages (\n id INTEGER PRIMARY KEY,\n symbol_id INTEGER NOT NULL,\n line INTEGER NOT NULL,\n column INTEGER NOT NULL,\n context TEXT NOT NULL,\n argument_count INTEGER,\n is_method_call INTEGER,\n is_constructor_call INTEGER,\n receiver_name TEXT,\n FOREIGN KEY (symbol_id) REFERENCES symbols(id)\n);\n\n-- Indexes for efficient queries\nCREATE INDEX idx_files_path ON files(path);\nCREATE INDEX idx_definitions_file ON definitions(file_id);\nCREATE INDEX idx_definitions_name ON definitions(name);\nCREATE INDEX idx_definitions_extends ON definitions(extends_name);\nCREATE INDEX idx_imports_from_file ON imports(from_file_id);\nCREATE INDEX idx_imports_to_file ON imports(to_file_id);\nCREATE INDEX idx_symbols_reference ON symbols(reference_id);\nCREATE INDEX idx_symbols_definition ON symbols(definition_id);\nCREATE INDEX idx_symbols_file ON symbols(file_id);\nCREATE INDEX idx_usages_symbol ON usages(symbol_id);\nCREATE INDEX idx_usages_context ON usages(context);\n\n-- Key-value metadata for definitions\nCREATE TABLE definition_metadata (\n id INTEGER PRIMARY KEY,\n definition_id INTEGER NOT NULL,\n key TEXT NOT NULL,\n value TEXT NOT NULL,\n FOREIGN KEY (definition_id) REFERENCES definitions(id) ON DELETE CASCADE,\n UNIQUE(definition_id, key)\n);\n\nCREATE INDEX idx_definition_metadata_def ON definition_metadata(definition_id);\nCREATE INDEX idx_definition_metadata_key ON definition_metadata(key);\n\n-- Semantic annotations for relationships between definitions\nCREATE TABLE relationship_annotations (\n id INTEGER PRIMARY KEY,\n from_definition_id INTEGER NOT NULL,\n to_definition_id INTEGER NOT NULL,\n relationship_type TEXT NOT NULL DEFAULT 'uses', -- 'uses' | 'extends' | 'implements'\n semantic TEXT NOT NULL,\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n FOREIGN KEY (from_definition_id) REFERENCES definitions(id) ON DELETE CASCADE,\n FOREIGN KEY (to_definition_id) REFERENCES definitions(id) ON DELETE CASCADE,\n UNIQUE(from_definition_id, to_definition_id)\n);\n\nCREATE INDEX idx_relationship_annotations_from ON relationship_annotations(from_definition_id);\nCREATE INDEX idx_relationship_annotations_to ON relationship_annotations(to_definition_id);\nCREATE INDEX idx_relationship_annotations_type ON relationship_annotations(relationship_type);\n\n-- Domain registry for managing business domains\nCREATE TABLE domains (\n id INTEGER PRIMARY KEY,\n name TEXT UNIQUE NOT NULL,\n description TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\nCREATE INDEX idx_domains_name ON domains(name);\n\n-- Module tree structure\nCREATE TABLE modules (\n id INTEGER PRIMARY KEY,\n parent_id INTEGER REFERENCES modules(id) ON DELETE CASCADE,\n slug TEXT NOT NULL, -- e.g., \"login\" (leaf segment)\n full_path TEXT NOT NULL UNIQUE, -- e.g., \"project.packages.electron-app.screens.login\"\n name TEXT NOT NULL, -- Human-readable: \"Login Screen\"\n description TEXT, -- Free text description\n depth INTEGER NOT NULL DEFAULT 0, -- 0 for root, 1 for children, etc.\n color_index INTEGER NOT NULL DEFAULT 0,\n is_test INTEGER NOT NULL DEFAULT 0, -- 1 if module exists solely for testing\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n UNIQUE(parent_id, slug)\n);\n\nCREATE INDEX idx_modules_parent ON modules(parent_id);\nCREATE INDEX idx_modules_path ON modules(full_path);\nCREATE INDEX idx_modules_depth ON modules(depth);\n\n-- Symbol assignments (each symbol belongs to exactly one module)\nCREATE TABLE module_members (\n module_id INTEGER NOT NULL REFERENCES modules(id) ON DELETE CASCADE,\n definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n assigned_at TEXT NOT NULL DEFAULT (datetime('now')),\n PRIMARY KEY (definition_id)\n);\n\nCREATE INDEX idx_module_members_module ON module_members(module_id);\n\n-- Communication contracts between process groups\nCREATE TABLE contracts (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n protocol TEXT NOT NULL,\n key TEXT NOT NULL,\n normalized_key TEXT NOT NULL,\n description TEXT,\n created_at TEXT DEFAULT (datetime('now')),\n UNIQUE(protocol, normalized_key)\n);\n\nCREATE INDEX idx_contracts_protocol ON contracts(protocol);\n\n-- Contract participants (definitions participating in a contract)\nCREATE TABLE contract_participants (\n id INTEGER PRIMARY KEY AUTOINCREMENT,\n contract_id INTEGER NOT NULL REFERENCES contracts(id) ON DELETE CASCADE,\n definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n module_id INTEGER REFERENCES modules(id) ON DELETE SET NULL,\n role TEXT NOT NULL,\n UNIQUE(contract_id, definition_id)\n);\n\nCREATE INDEX idx_cp_contract ON contract_participants(contract_id);\nCREATE INDEX idx_cp_definition ON contract_participants(definition_id);\nCREATE INDEX idx_cp_module ON contract_participants(module_id);\n\n-- Interactions: module-to-module edges (flat, not hierarchical)\nCREATE TABLE interactions (\n id INTEGER PRIMARY KEY,\n from_module_id INTEGER NOT NULL REFERENCES modules(id) ON DELETE CASCADE,\n to_module_id INTEGER NOT NULL REFERENCES modules(id) ON DELETE CASCADE,\n direction TEXT NOT NULL DEFAULT 'uni', -- 'uni' | 'bi'\n weight INTEGER NOT NULL DEFAULT 1,\n pattern TEXT, -- 'utility' | 'business'\n symbols TEXT, -- JSON array of symbol names\n semantic TEXT, -- What happens in this interaction\n source TEXT NOT NULL DEFAULT 'ast', -- 'ast' | 'llm-inferred'\n confidence TEXT, -- 'high' | 'medium' | NULL\n created_at TEXT NOT NULL DEFAULT (datetime('now')),\n UNIQUE(from_module_id, to_module_id)\n);\n\nCREATE INDEX idx_interactions_from_module ON interactions(from_module_id);\nCREATE INDEX idx_interactions_to_module ON interactions(to_module_id);\nCREATE INDEX idx_interactions_pattern ON interactions(pattern);\nCREATE INDEX idx_interactions_source ON interactions(source);\n\n-- Links contract-matched interactions to specific definition pairs\nCREATE TABLE interaction_definition_links (\n interaction_id INTEGER NOT NULL REFERENCES interactions(id) ON DELETE CASCADE,\n from_definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n to_definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n contract_id INTEGER REFERENCES contracts(id) ON DELETE SET NULL,\n PRIMARY KEY (interaction_id, from_definition_id, to_definition_id)\n);\n\nCREATE INDEX idx_idl_interaction ON interaction_definition_links(interaction_id);\n\n-- Flows: user journeys with entry points\nCREATE TABLE flows (\n id INTEGER PRIMARY KEY,\n name TEXT NOT NULL,\n slug TEXT NOT NULL UNIQUE,\n entry_point_module_id INTEGER REFERENCES modules(id) ON DELETE SET NULL,\n entry_point_id INTEGER REFERENCES definitions(id) ON DELETE SET NULL,\n entry_path TEXT, -- e.g., \"POST /api/auth/login\"\n stakeholder TEXT, -- 'user' | 'admin' | 'system' | 'developer' | 'external'\n description TEXT,\n created_at TEXT NOT NULL DEFAULT (datetime('now'))\n);\n\nCREATE INDEX idx_flows_slug ON flows(slug);\nCREATE INDEX idx_flows_entry_point_module ON flows(entry_point_module_id);\nCREATE INDEX idx_flows_entry_point ON flows(entry_point_id);\nCREATE INDEX idx_flows_stakeholder ON flows(stakeholder);\n\n-- Flow steps: ordered interactions within a flow (module-level)\nCREATE TABLE flow_steps (\n flow_id INTEGER NOT NULL REFERENCES flows(id) ON DELETE CASCADE,\n step_order INTEGER NOT NULL,\n interaction_id INTEGER NOT NULL REFERENCES interactions(id) ON DELETE CASCADE,\n PRIMARY KEY (flow_id, step_order)\n);\n\nCREATE INDEX idx_flow_steps_interaction ON flow_steps(interaction_id);\n\n-- Flow definition steps: ordered definition-level call edges within a flow\nCREATE TABLE flow_definition_steps (\n flow_id INTEGER NOT NULL REFERENCES flows(id) ON DELETE CASCADE,\n step_order INTEGER NOT NULL,\n from_definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n to_definition_id INTEGER NOT NULL REFERENCES definitions(id) ON DELETE CASCADE,\n PRIMARY KEY (flow_id, step_order)\n);\n\nCREATE INDEX idx_flow_def_steps_from ON flow_definition_steps(from_definition_id);\nCREATE INDEX idx_flow_def_steps_to ON flow_definition_steps(to_definition_id);\n\n-- Incremental sync dirty tracking\nCREATE TABLE sync_dirty (\n layer TEXT NOT NULL,\n entity_id INTEGER NOT NULL,\n reason TEXT NOT NULL,\n PRIMARY KEY (layer, entity_id)\n);\n"; /** * Predicate that identifies runtime interactions (as opposed to static import edges). * Keeps 'ast', 'llm-inferred', and 'contract-matched' sources; excludes 'ast-import' source and 'test-internal' pattern. * This is the single source of truth for "meaningful interaction" across the entire pipeline. */ export declare function isRuntimeInteraction(i: Pick): boolean; export declare function computeHash(content: string): string; //# sourceMappingURL=schema.d.ts.map